diff --git a/History.md b/History.md index cb31a4a..16994ee 100644 --- a/History.md +++ b/History.md @@ -1,3 +1,6 @@ +- 0.12.0 2014-10-09 + Checking for existence of del() method before binding to it. Fixes #11. + - 0.11.0 2014-09-18 Prevent stalemate by executing callbacks on error. Fixes #10 - elliotttf diff --git a/lib/caching.js b/lib/caching.js index 266b987..9827641 100644 --- a/lib/caching.js +++ b/lib/caching.js @@ -1,4 +1,4 @@ -/*jshint maxcomplexity:10*/ +/*jshint maxcomplexity:15*/ var caching = function (args) { args = args || {}; var self = {}; @@ -78,7 +78,9 @@ var caching = function (args) { self.set = self.store.set.bind(self.store); - self.del = self.store.del.bind(self.store); + if (typeof self.store.del === 'function') { + self.del = self.store.del.bind(self.store); + } if (typeof self.store.setex === 'function') { self.setex = self.store.setex.bind(self.store); diff --git a/package.json b/package.json index 932d404..875b149 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cache-manager", - "version": "0.11.0", + "version": "0.12.0", "description": "Cache module for Node.js", "main": "index.js", "scripts": { diff --git a/test/caching.unit.js b/test/caching.unit.js index 756fb55..16d22b5 100644 --- a/test/caching.unit.js +++ b/test/caching.unit.js @@ -145,6 +145,23 @@ describe("caching", function () { }); }, 10); }); + + context("when store has no del() method", function () { + var fake_store; + + beforeEach(function () { + fake_store = { + get: function () {}, + set: function () {}, + }; + }); + + it("it doesn't throw an error", function () { + assert.doesNotThrow(function () { + caching({store: fake_store}); + }); + }); + }); }); describe("setex()", function () {