diff --git a/lib/bootstrap.js b/lib/bootstrap.js index 36eadb2..b72d338 100644 --- a/lib/bootstrap.js +++ b/lib/bootstrap.js @@ -11,9 +11,6 @@ var parameterMiddleware = require('./parameters/middleware'); var Injector = require('./util/di/Injector'); var RoutesLoader = require('./routing/RoutesLoader'); -var Cache = require('./caching/Cache'); -var createCachingMiddlewares = require('./util/cachingMiddlewares'); - var resultHandler = require('./result/resultHandler'); var errorHandler = require('./result/errorHandler'); @@ -38,20 +35,13 @@ function bootstrap (app, configuration, callback) { function _setup (app, db, mqttClient, configuration) { var injector = _createInjector(db, mqttClient, configuration); - var cache = new Cache(); - var cacheMiddlewares = createCachingMiddlewares(cache, configuration); - app.use(initMiddleware()); app.use(parameterMiddleware()); - app.use(cacheMiddlewares.pre); - new RoutesLoader(path.join(__dirname, 'routes'), injector) .load() .mount(app); - app.use(cacheMiddlewares.post); - app.use(resultHandler); app.use(errorHandler); } diff --git a/lib/caching/Cache.js b/lib/caching/Cache.js deleted file mode 100644 index e276454..0000000 --- a/lib/caching/Cache.js +++ /dev/null @@ -1,25 +0,0 @@ -function Cache() { - this._cache = {}; -} - -Cache.prototype.set = function(key, parameters, value) { - if (!this._cache[key]) this._cache[key] = {}; - - if (!parameters) parameters = ''; - - this._cache[key][parameters] = value; -}; - -Cache.prototype.get = function(key, parameters) { - if (!parameters) parameters = ''; - - return (this._cache[key] && this._cache[key][parameters]) || null; -}; - -Cache.prototype.clear = function(key) { - if (this._cache[key]) { - delete this._cache[key]; - } -}; - -module.exports = Cache; \ No newline at end of file diff --git a/lib/caching/middlewares.js b/lib/caching/middlewares.js deleted file mode 100644 index d986e78..0000000 --- a/lib/caching/middlewares.js +++ /dev/null @@ -1,20 +0,0 @@ -function createPreMiddleware () { - return function (req, res, next) { - next(); - }; -} - -function createPostMiddleware() { - return function (req, res, next) { - next(); - }; -} - -function cacheMiddlewares (cache, configuration) { - return { - pre: createPreMiddleware(cache), - post: createPostMiddleware(cache) - }; -} - -module.exports = cacheMiddlewares; \ No newline at end of file diff --git a/lib/util/cachingMiddlewares.js b/lib/util/cachingMiddlewares.js deleted file mode 100644 index 37204f8..0000000 --- a/lib/util/cachingMiddlewares.js +++ /dev/null @@ -1,21 +0,0 @@ -var cachingMiddlewares = require('../caching/middlewares'); - -function cachingMiddlewaresNoop() { - return { - pre: function(req, res, next) { - next(); - }, - - post: function(req, res, next) { - next(); - } - } -} - -function cacheMiddlewares(cache, configuration) { - if (!configuration.caching.enabled) return cachingMiddlewaresNoop(); - - return cachingMiddlewares(cache, configuration); -} - -module.exports = cacheMiddlewares; \ No newline at end of file diff --git a/tests/unit/caching.tests.js b/tests/unit/caching.tests.js deleted file mode 100644 index 3dbd7e6..0000000 --- a/tests/unit/caching.tests.js +++ /dev/null @@ -1,48 +0,0 @@ -var expect = require('chai').use(require('sinon-chai')).expect; -var sinon = require('sinon'); - -var Cache = require('../../lib/caching/Cache'); - -describe('caching', function() { - describe('cache set/get', function() { - var c; - - before(function() { - c = new Cache(); - - c.set('/a/b', null, 'ab'); - c.set('/a/b', 'foobar', 'foobar'); - }); - - it('should hold a value', function() { - expect(c.get('/a/b', null)).to.equal('ab'); - }); - - it('should hold a value /w parameters', function() { - expect(c.get('/a/b', 'foobar')).to.equal('foobar'); - }); - }); - - describe('cache /w clear', function() { - var c; - - before(function() { - c = new Cache(); - - c.set('/a/b', null, 'ab'); - c.set('/a/b', 'foobar', 'foobar'); - c.set('/a/c', null, 'ac'); - - c.clear('/a/b'); - }); - - it('should have cleared all items from the same route', function() { - expect(c.get('/a/b', null)).to.be.null; - expect(c.get('/a/b', 'foobar')).to.be.null; - }); - - it('should have hold on to the other route', function() { - expect(c.get('/a/c', null)).to.equal('ac'); - }); - }); -}); \ No newline at end of file