diff --git a/cache/index.js b/cache/index.js deleted file mode 100644 index e7c08b0..0000000 --- a/cache/index.js +++ /dev/null @@ -1,67 +0,0 @@ -'use strict'; - -var cache = require('volos-cache-memory'); -var async = require('async'); -var debug = require('debug')('gateway:cache'); - -var getKey = function (req) { - return req.token.application_name; -} -var caches = []; - -var middleware = function (req, res, next) { - if (!req.token - || !req.token.api_product_list - || !req.token.api_product_list.length - ) { - return next(); - } - - debug('cache checking products', req.token.api_product_list); - - req.originalUrl = req.originalUrl || req.url; // emulate connect - - var found = false; - // this is arbitrary, but not sure there's a better way? - async.eachSeries(req.token.api_product_list, - function (productName, cb) { - if(!found) { - var cache = caches[productName]; - executeDefaultCache(cache, req, res, cb); - found = true; - }else{ - cb(); - } - }, - function (err) { - next(err); - } - ); -} - -var executeDefaultCache = function (cache, req, res, cb) { - cb(); -}; - -module.exports.init = function (config, logger, stats) { - var options = { - key: getKey - }; - Object.keys(config).forEach(function (productName) { - var product = config[productName]; - if (!product.ttl) { - debug('could not load cache for ' + productName + ' because ttl is missing', product) - return; // skip non-cache config - } - var cacheInstance = cache.create(config[productName]); - caches[productName] = cacheInstance; - debug('created cache for', productName); - debug('caches are ', caches) - }); - - return { - onrequest: function (req, res, next) { - middleware(req, res, next); - } - }; -}; \ No newline at end of file diff --git a/cache/package.json b/cache/package.json deleted file mode 100644 index 7516753..0000000 --- a/cache/package.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "name": "edgemicro-plugin-cache", - "version": "1.0.0", - "description": "caching plugin for the gateway", - "main": "index.js", - "scripts": { - "test": "mocha tests" - }, - "author": "sfeldman@apigee.com", - "dependencies": { - "async": "^1.5.2", - "debug": "^2.2.0", - "volos-cache-memory": "^0.10.0" - }, - "devDependencies": { - "mocha": "^2.4.5", - "should": "^8.2.1" - } -} diff --git a/cache/tests/testIndex.js b/cache/tests/testIndex.js deleted file mode 100644 index a55c654..0000000 --- a/cache/tests/testIndex.js +++ /dev/null @@ -1,12 +0,0 @@ -var should = require('should'); -var assert = require('assert'); -var plugin = require('../index'); -describe('construct',function(){ - it('should work',function(done){ - var req = plugin.init(); - req.onrequest(null,null,function(err){ - should(err).be.null - done(); - }) - }) ; -}); \ No newline at end of file diff --git a/index.js b/index.js index ca049b7..7e77135 100644 --- a/index.js +++ b/index.js @@ -4,11 +4,10 @@ module.exports = { 'accumulate-request':require('./accumulate-request'), 'accumulate-response':require('./accumulate-response'), analytics:require('./analytics'), - cache:require('./cache'), 'header-uppercase':require('./header-uppercase'), oauth:require('./oauth'), quota:require('./quota'), 'quota-memory':require('./quota-memory'), spikearrest:require('./spikearrest'), 'transform-uppercase':require('./transform-uppercase') -} \ No newline at end of file +}