cache-manager
Advanced tools
Comparing version 1.4.0 to 1.4.1
@@ -0,1 +1,4 @@ | ||
- 1.4.1 2016-03-13 | ||
- Fixing backward-compatibility Promise issue with node 0.10.x in memory store. | ||
- 1.4.0 2016-02-03 | ||
@@ -2,0 +5,0 @@ - Passing ttl of 0 to lruCache, upgrading to lru-cache 4.0.0 |
@@ -7,2 +7,4 @@ var Lru = require("lru-cache"); | ||
self.name = 'memory'; | ||
self.usePromises = (typeof Promise === 'undefined' || args.noPromises) ? false : true; | ||
var ttl = args.ttl; | ||
@@ -31,3 +33,3 @@ var lruOpts = { | ||
process.nextTick(cb); | ||
} else { | ||
} else if (self.usePromises) { | ||
return Promise.resolve(value); | ||
@@ -47,2 +49,4 @@ } | ||
}); | ||
} else if (self.usePromises) { | ||
return Promise.resolve(value); | ||
} else { | ||
@@ -57,5 +61,9 @@ return value; | ||
} | ||
lruCache.del(key); | ||
if (cb) { | ||
process.nextTick(cb); | ||
} else if (self.usePromises) { | ||
return Promise.resolve(); | ||
} | ||
@@ -68,2 +76,4 @@ }; | ||
process.nextTick(cb); | ||
} else if (self.usePromises) { | ||
return Promise.resolve(); | ||
} | ||
@@ -78,2 +88,4 @@ }; | ||
}); | ||
} else if (self.usePromises) { | ||
return Promise.resolve(keys); | ||
} else { | ||
@@ -80,0 +92,0 @@ return keys; |
{ | ||
"name": "cache-manager", | ||
"version": "1.4.0", | ||
"version": "1.4.1", | ||
"description": "Cache module for Node.js", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -158,4 +158,6 @@ [![build status](https://secure.travis-ci.org/BryanDonovan/node-cache-manager.png)](http://travis-ci.org/BryanDonovan/node-cache-manager) | ||
Here's a very basic example of how you could use this in an Express app: | ||
#### Example Express App Usage | ||
(Also see the [Express.js cache-manager example app](https://github.com/BryanDonovan/node-cache-manager-express-example)). | ||
```javascript | ||
@@ -162,0 +164,0 @@ function respond(res, err, data) { |
@@ -48,2 +48,3 @@ // TODO: These are really a mix of unit and integration tests. | ||
it("lets us set and get data without a callback", function(done) { | ||
cache = caching({store: memoryStore.create({noPromises: true})}); | ||
cache.set(key, value, {ttl: defaultTtl}); | ||
@@ -58,3 +59,15 @@ | ||
it("lets us set and get data without a callback, returning a promise", function(done) { | ||
cache.set(key, value, {ttl: defaultTtl}); | ||
setTimeout(function() { | ||
cache.get(key) | ||
.then(function(result) { | ||
assert.equal(result, value); | ||
done(); | ||
}); | ||
}, 20); | ||
}); | ||
it("lets us set and get data without options object or callback", function(done) { | ||
cache = caching({store: memoryStore.create({noPromises: true})}); | ||
cache.set(key, value); | ||
@@ -229,6 +242,7 @@ | ||
var keyCount; | ||
var savedKeys = []; | ||
var savedKeys; | ||
beforeEach(function(done) { | ||
keyCount = 10; | ||
savedKeys = []; | ||
var processed = 0; | ||
@@ -254,3 +268,3 @@ | ||
checkErr(err); | ||
assert.deepEqual(keys.sort, savedKeys.sort); | ||
assert.deepEqual(keys.sort(), savedKeys.sort()); | ||
done(); | ||
@@ -260,6 +274,39 @@ }); | ||
it("lets us get the keys without a callback (memory store only)", function() { | ||
var keys = cache.keys(); | ||
assert.deepEqual(keys.sort, savedKeys.sort); | ||
it("lets us set and get data without a callback, returning a promise", function(done) { | ||
cache.keys() | ||
.then(function(keys) { | ||
assert.deepEqual(keys.sort(), savedKeys.sort()); | ||
done(); | ||
}) | ||
.catch(function(err) { | ||
done(err); | ||
}); | ||
}); | ||
context("when not using promises", function() { | ||
beforeEach(function(done) { | ||
savedKeys = []; | ||
keyCount = 10; | ||
var processed = 0; | ||
cache = caching({store: memoryStore.create({noPromises: true})}); | ||
function isDone() { | ||
return processed === keyCount; | ||
} | ||
async.until(isDone, function(cb) { | ||
processed += 1; | ||
key = support.random.string(20); | ||
savedKeys.push(key); | ||
value = support.random.string(); | ||
cache.set(key, value, cb); | ||
}, done); | ||
}); | ||
it("lets us get the keys without a callback (memory store only)", function() { | ||
var keys = cache.keys(); | ||
assert.deepEqual(keys.sort(), savedKeys.sort()); | ||
}); | ||
}); | ||
}); | ||
@@ -266,0 +313,0 @@ |
@@ -377,3 +377,6 @@ var assert = require('assert'); | ||
process.nextTick(function() { | ||
assert.equal(memoryCache.get(key), value); | ||
memoryCache.get(key) | ||
.then(function(fetchedValue) { | ||
assert.equal(fetchedValue, value); | ||
}); | ||
}); | ||
@@ -380,0 +383,0 @@ }) |
@@ -0,1 +1,2 @@ | ||
var assert = require('assert'); | ||
var support = require('../support'); | ||
@@ -11,2 +12,20 @@ var memoryStore = require('../../lib/stores/memory'); | ||
}); | ||
describe("set()", function() { | ||
var memoryCache; | ||
beforeEach(function() { | ||
memoryCache = memoryStore.create({noPromises: true}); | ||
}); | ||
// This test should pass in node v0.10.x: | ||
it("does not require a callback or use of Promises", function(done) { | ||
memoryCache.set('foo', 'bar'); | ||
setTimeout(function() { | ||
assert.equal(memoryCache.get('foo'), 'bar'); | ||
done(); | ||
}, 10); | ||
}); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
131327
2822
295