Browse Source

adding reset() function for issue #5

feature/nested-cache-fetch-fix
Bryan Donovan 11 years ago
parent
commit
30678a1684
  1. 4
      lib/caching.js
  2. 7
      lib/stores/memory.js
  3. 52
      test/caching.unit.js

4
lib/caching.js

@ -57,6 +57,10 @@ var caching = function (args) {
self.del = self.store.del.bind(self.store);
if (typeof self.store.reset === 'function') {
self.reset = self.store.reset.bind(self.store);
}
return self;
};

7
lib/stores/memory.js

@ -32,6 +32,13 @@ var memory_store = function (args) {
}
};
self.reset = function (cb) {
lru_cache.reset();
if (cb) {
process.nextTick(cb);
}
};
return self;
};

52
test/caching.unit.js

@ -1,3 +1,5 @@
// TODO: These are really a mix of unit and integration tests.
var assert = require('assert');
var sinon = require('sinon');
var support = require('./support');
@ -96,6 +98,55 @@ describe("caching", function () {
});
});
describe("reset()", function () {
var key2;
var value2;
beforeEach(function (done) {
cache = caching({store: 'memory'});
key = support.random.string(20);
value = support.random.string();
cache.set(key, value, function (err) {
check_err(err);
key2 = support.random.string(20);
value2 = support.random.string();
cache.set(key, value, done);
});
});
it("clears the cache", function (done) {
cache.reset(function (err) {
check_err(err);
cache.get(key, function (err, result) {
assert.ok(!result);
cache.get(key2, function (err, result) {
assert.ok(!result);
done();
});
});
});
});
it("lets us clear the cache without a callback", function (done) {
cache.reset();
setTimeout(function () {
cache.get(key, function (err, result) {
assert.ok(!result);
cache.get(key2, function (err, result) {
assert.ok(!result);
done();
});
});
}, 10);
});
});
describe("wrap()", function () {
describe("using memory (lru-cache) store", function () {
var memory_store_stub;
@ -282,7 +333,6 @@ describe("caching", function () {
});
});
});
});
});

Loading…
Cancel
Save