From 59e5a0188cd8f7463ebcd7ef0ec3eff283da4cbb Mon Sep 17 00:00:00 2001 From: Evan Lucas Date: Thu, 26 Jun 2014 10:02:54 -0500 Subject: [PATCH 1/2] Expose setex if exists and is a function This allows us to use the cache store with a ttl on some transactions, but not all. --- lib/caching.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/caching.js b/lib/caching.js index f410a19..72e6a70 100644 --- a/lib/caching.js +++ b/lib/caching.js @@ -58,6 +58,10 @@ var caching = function (args) { self.del = self.store.del.bind(self.store); + if (typeof self.store.setex === 'function') { + self.setex = self.store.setex.bind(self.store); + } + if (typeof self.store.reset === 'function') { self.reset = self.store.reset.bind(self.store); } From 48d6b4b829f3e3edf7edbff67e64cd86eb6d9096 Mon Sep 17 00:00:00 2001 From: Bryan Donovan Date: Mon, 7 Jul 2014 10:08:44 -0700 Subject: [PATCH 2/2] unit test for setex() --- test/caching.unit.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/test/caching.unit.js b/test/caching.unit.js index 5f1f5dc..54b0df4 100644 --- a/test/caching.unit.js +++ b/test/caching.unit.js @@ -147,6 +147,28 @@ describe("caching", function () { }); }); + describe("setex()", function () { + var fake_store; + + beforeEach(function () { + fake_store = { + get: function () {}, + set: function () {}, + del: function () {}, + setex: function () {} + }; + + sinon.stub(fake_store, 'setex'); + + cache = caching({store: fake_store}); + }); + + it("passes the params to the underlying store's setex() method", function () { + cache.setex('foo', 'bar', 'blah'); + assert.ok(fake_store.setex.calledWith('foo', 'bar', 'blah')); + }); + }); + describe("keys()", function () { var key_count; var saved_keys = [];