Browse Source

testing that we can use set() and del() without a callback

hotfix/0.7.1
Bryan Donovan 12 years ago
parent
commit
773e3f95b1
  1. 2
      README.md
  2. 8
      lib/stores/memory.js
  3. 25
      test/caching.unit.js

2
README.md

@ -49,6 +49,8 @@ node-cache-manager handles easily and transparently.
var redis_cache = cache_manager.caching({store: 'redis', db: 1, ttl: 100/*seconds*/});
var memory_cache = cache_manager.caching({store: 'memory', max: 100, ttl: 10/*seconds*/});
// Note: callback is optional in set() and del().
redis_cache.set('foo', 'bar', function(err) {
if (err) { throw err; }

8
lib/stores/memory.js

@ -14,7 +14,9 @@ var memory_store = function (args) {
self.set = function (key, value, cb) {
lru_cache.set(key, value);
cb(null);
if (cb) {
cb(null);
}
};
self.get = function (key, cb) {
@ -23,7 +25,9 @@ var memory_store = function (args) {
self.del = function (key, cb) {
lru_cache.del(key);
cb(null);
if (cb) {
cb(null);
}
};
return self;

25
test/caching.unit.js

@ -35,6 +35,16 @@ describe("caching", function () {
});
});
});
it("lets us set data without a callback", function (done) {
cache.set(key, value);
setTimeout(function () {
cache.get(key, function (err, result) {
assert.equal(result, value);
done();
});
}, 20);
});
});
});
});
@ -66,6 +76,21 @@ describe("caching", function () {
});
});
});
it("lets us delete data without a callback", function (done) {
cache.get(key, function (err, result) {
assert.equal(result, value);
cache.del(key);
setTimeout(function () {
cache.get(key, function (err, result) {
assert.ok(!result);
done();
});
}, 20);
});
});
});
});
});

Loading…
Cancel
Save