memoize-cache
Advanced tools
Comparing version 3.1.0 to 3.1.1
18
cache.js
@@ -45,2 +45,4 @@ var Promise = require('bluebird'); | ||
var that = this; | ||
var alreadyCalledCB = false; | ||
var obj; | ||
@@ -64,3 +66,3 @@ if (key === null) { | ||
if (res) { | ||
next(null, { | ||
obj = { | ||
cached: true, | ||
@@ -70,5 +72,8 @@ key: key, | ||
stale: Boolean(res.maxValidity && res.maxValidity < Date.now()) | ||
}); | ||
}; | ||
alreadyCalledCB = true; | ||
next(null, obj); | ||
} | ||
else { | ||
alreadyCalledCB = true; | ||
next(null, { | ||
@@ -81,3 +86,10 @@ cached: false, | ||
.catch(function (err) { | ||
next(err); | ||
if (!alreadyCalledCB) { | ||
next(err); | ||
} | ||
else { | ||
setTimeout(function () { | ||
throw(err); | ||
}, 0); | ||
} | ||
}); | ||
@@ -84,0 +96,0 @@ }; |
{ | ||
"name": "memoize-cache", | ||
"version": "3.1.0", | ||
"version": "3.1.1", | ||
"description": "A cache support for memoized functions", | ||
@@ -30,4 +30,3 @@ "main": "index.js", | ||
"mocha": "^2.1.0", | ||
"npm-release": "^1.0.0", | ||
"snappy": "^5.0.3" | ||
"npm-release": "^1.0.0" | ||
}, | ||
@@ -34,0 +33,0 @@ "dependencies": { |
@@ -106,3 +106,5 @@ var sizeof = require('sizeof'); | ||
lru, | ||
key; | ||
key, | ||
alreadyCalledCB = false; | ||
try { | ||
@@ -115,2 +117,3 @@ this._purgeByAge(); // purge stale cache entries | ||
// if k is null I don't cache | ||
alreadyCalledCB = true; | ||
return next(null, { | ||
@@ -134,3 +137,8 @@ cached: false, | ||
catch (e) { | ||
return next(e); | ||
if (!alreadyCalledCB) { | ||
return next(e); | ||
} | ||
else { | ||
throw(e); | ||
} | ||
} | ||
@@ -137,0 +145,0 @@ |
@@ -5,3 +5,3 @@ var assert = require('chai').assert; | ||
var lzma = require('lzma-purejs'); | ||
var snappy = require('snappy'); | ||
// var snappy = require('snappy'); | ||
@@ -394,26 +394,26 @@ describe('cache-manager', function () { | ||
it('must serialize/deserialize data with snappy', function (done) { | ||
var memoryCache = cacheManager.caching({store: 'memory', max: 100, ttl: 10}); | ||
var serialize = function (obj) { | ||
var data = new Buffer(JSON.stringify(obj), 'utf8'); | ||
var compressed = snappy.compressSync(data); | ||
return compressed; | ||
}; | ||
var deserialize = function (buf) { | ||
var uncompressed = snappy.uncompressSync(buf); | ||
var data2 = new Buffer(uncompressed).toString('utf8'); | ||
return JSON.parse(data2); | ||
}; | ||
var cache = new Cache(memoryCache, {serialize: serialize, deserialize: deserialize}); | ||
cache.push([], 'result'); | ||
cache.query({}, function (err, res) { | ||
assert.equal(res.cached, true); | ||
assert.equal(res.key, '_default'); | ||
assert.equal(res.hit, 'result'); | ||
done(); | ||
}); | ||
}); | ||
// it('must serialize/deserialize data with snappy', function (done) { | ||
// var memoryCache = cacheManager.caching({store: 'memory', max: 100, ttl: 10}); | ||
// | ||
// var serialize = function (obj) { | ||
// var data = new Buffer(JSON.stringify(obj), 'utf8'); | ||
// var compressed = snappy.compressSync(data); | ||
// return compressed; | ||
// }; | ||
// | ||
// var deserialize = function (buf) { | ||
// var uncompressed = snappy.uncompressSync(buf); | ||
// var data2 = new Buffer(uncompressed).toString('utf8'); | ||
// return JSON.parse(data2); | ||
// }; | ||
// | ||
// var cache = new Cache(memoryCache, {serialize: serialize, deserialize: deserialize}); | ||
// cache.push([], 'result'); | ||
// cache.query({}, function (err, res) { | ||
// assert.equal(res.cached, true); | ||
// assert.equal(res.key, '_default'); | ||
// assert.equal(res.hit, 'result'); | ||
// done(); | ||
// }); | ||
// }); | ||
}); |
var assert = require('chai').assert; | ||
var Cache = require('../ram-cache'); | ||
var lzma = require('lzma-purejs'); | ||
var snappy = require('snappy'); | ||
// var snappy = require('snappy'); | ||
@@ -404,24 +404,24 @@ describe('cache', function () { | ||
it('must serialize/deserialize data with snappy', function (done) { | ||
var serialize = function (obj) { | ||
var data = new Buffer(JSON.stringify(obj), 'utf8'); | ||
var compressed = snappy.compressSync(data); | ||
return compressed; | ||
}; | ||
var deserialize = function (buf) { | ||
var uncompressed = snappy.uncompressSync(buf); | ||
var data2 = new Buffer(uncompressed).toString('utf8'); | ||
return JSON.parse(data2); | ||
}; | ||
var cache = new Cache({serialize: serialize, deserialize: deserialize}); | ||
cache.push([], 'result'); | ||
cache.query({}, function (err, res) { | ||
assert.equal(res.cached, true); | ||
assert.equal(res.key, '_default'); | ||
assert.equal(res.hit, 'result'); | ||
done(); | ||
}); | ||
}); | ||
// it('must serialize/deserialize data with snappy', function (done) { | ||
// var serialize = function (obj) { | ||
// var data = new Buffer(JSON.stringify(obj), 'utf8'); | ||
// var compressed = snappy.compressSync(data); | ||
// return compressed; | ||
// }; | ||
// | ||
// var deserialize = function (buf) { | ||
// var uncompressed = snappy.uncompressSync(buf); | ||
// var data2 = new Buffer(uncompressed).toString('utf8'); | ||
// return JSON.parse(data2); | ||
// }; | ||
// | ||
// var cache = new Cache({serialize: serialize, deserialize: deserialize}); | ||
// cache.push([], 'result'); | ||
// cache.query({}, function (err, res) { | ||
// assert.equal(res.cached, true); | ||
// assert.equal(res.key, '_default'); | ||
// assert.equal(res.hit, 'result'); | ||
// done(); | ||
// }); | ||
// }); | ||
}); |
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
50005
7
1275