Browse Source

Merge branch 'dial-once-master'

feature/fix-isCacheableValue-usage
Bryan Donovan 10 years ago
parent
commit
89794d8560
  1. 4
      examples/redis_example/redis_store.js
  2. 2
      lib/caching.js
  3. 21
      test/caching.unit.js

4
examples/redis_example/redis_store.js

@ -110,6 +110,10 @@ function redisStore(args) {
}); });
}; };
self.isCacheableValue = function(value) {
return value !== null && value !== undefined;
};
return self; return self;
} }

2
lib/caching.js

@ -34,6 +34,8 @@ var caching = function(args) {
if (typeof args.isCacheableValue === 'function') { if (typeof args.isCacheableValue === 'function') {
self._isCacheableValue = args.isCacheableValue; self._isCacheableValue = args.isCacheableValue;
} else if (typeof self.store.isCacheableValue === 'function') {
self._isCacheableValue = self.store.isCacheableValue;
} else { } else {
self._isCacheableValue = function(value) { self._isCacheableValue = function(value) {
return value !== undefined; return value !== undefined;

21
test/caching.unit.js

@ -707,4 +707,25 @@ describe("caching", function() {
}); });
}); });
}); });
describe("overloading with custom store", function() {
it("allows us to override isCacheableValue", function(done) {
var store = memoryStore.create({ttl: defaultTtl});
var onlyOne = true;
store.isCacheableValue = function(result) {
if (onlyOne) {
onlyOne = false;
done();
}
return result !== undefined;
};
cache = caching({store: store});
cache.wrap(key, function(cb) {
methods.getWidget(name, cb);
}, function(err, widget) {
checkErr(err);
assert.deepEqual(widget, {name: name});
});
});
});
}); });

Loading…
Cancel
Save