diff --git a/lib/multi_caching.js b/lib/multi_caching.js index 4cb4b77..7347b1b 100644 --- a/lib/multi_caching.js +++ b/lib/multi_caching.js @@ -43,10 +43,9 @@ var multi_caching = function (caches) { return cb(err); } - result = result || {}; cb(err, result); - if (result && index) { + if (result !== undefined && index) { var cachesToUpdate = caches.slice(0, index); async.forEach(cachesToUpdate, function(cache, async_cb) { cache.set(key, result, result.ttl, async_cb); diff --git a/test/multi_caching.unit.js b/test/multi_caching.unit.js index 37ba211..62efce3 100644 --- a/test/multi_caching.unit.js +++ b/test/multi_caching.unit.js @@ -202,6 +202,42 @@ describe("multi_caching", function () { }); }); + describe("when value is not found in any cache", function() { + var response; + + beforeEach(function(done) { + key = support.random.string(10); + sinon.spy(memory_cache, 'set'); + sinon.spy(memory_cache2, 'set'); + sinon.spy(memory_cache3, 'set'); + + multi_cache.get_and_pass_up(key, function (err, result) { + check_err(err); + response = result; + done(); + }); + }); + + afterEach(function() { + memory_cache.set.restore(); + memory_cache2.set.restore(); + memory_cache3.set.restore(); + }); + + it("calls back with undefined", function() { + assert.strictEqual(response, undefined); + }); + + it("does not set anything in caches", function(done) { + process.nextTick(function () { + assert.ok(memory_cache.set.notCalled); + assert.ok(memory_cache2.set.notCalled); + assert.ok(memory_cache3.set.notCalled); + done(); + }); + }); + }); + describe("using multi cache store", function () { beforeEach(function () { multi_cache = multi_caching([memory_cache,memory_cache2,memory_cache3]);