From d38e274a30a1efa17d55b7cf6add38f317a6be08 Mon Sep 17 00:00:00 2001 From: Bryan Donovan Date: Thu, 9 Oct 2014 09:27:17 -0700 Subject: [PATCH 1/2] checking for existence of del() method before binding to it --- lib/caching.js | 6 ++++-- test/caching.unit.js | 17 +++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) 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/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 () { From a731c3caafc85a77da8876e5037bc967097fec87 Mon Sep 17 00:00:00 2001 From: Bryan Donovan Date: Thu, 9 Oct 2014 09:28:18 -0700 Subject: [PATCH 2/2] v0.12.0 release notes --- History.md | 3 +++ package.json | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) 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/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": {