Browse Source

fixing handling of falsy valus in get_and_pass_up

feature/nested-cache-fetch-fix
Raadad Elsleiman 10 years ago
parent
commit
9bca5e674a
  1. 3
      lib/multi_caching.js
  2. 36
      test/multi_caching.unit.js

3
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);

36
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]);

Loading…
Cancel
Save