@nrk/nodecache-as-promised
Advanced tools
Comparing version 1.0.4 to 1.0.5
@@ -199,6 +199,7 @@ 'use strict'; | ||
})); | ||
(0, _expect2.default)(cacheInstance.waiting.get(dummyKey)).to.be.a('undefined'); | ||
const info = cacheInstance.debug(); | ||
(0, _expect2.default)(info.waiting.get(dummyKey)).to.be.a('undefined'); | ||
return cacheInstance.get(dummyKey, { workerTimeout: 0, worker: timeoutSpy }).then(obj => { | ||
(0, _expect2.default)(timeoutSpy.called).to.equal(true); | ||
(0, _expect2.default)(cacheInstance.waiting.get(dummyKey)).not.to.equal(0); | ||
(0, _expect2.default)(info.waiting.get(dummyKey)).not.to.equal(0); | ||
(0, _expect2.default)(obj.value).to.eql(cacheValue); | ||
@@ -231,3 +232,4 @@ (0, _expect2.default)(obj.cache).to.equal('stale'); | ||
(0, _expect2.default)(obj.value).to.eql(cacheValue); | ||
(0, _expect2.default)(cacheInstance.waiting.get(dummyKey).wait).to.equal(10); | ||
const info = cacheInstance.debug(); | ||
(0, _expect2.default)(info.waiting.get(dummyKey).wait).to.equal(10); | ||
return cacheInstance.get(dummyKey, _extends({}, conf, { worker: resolveSpy })).then(obj => { | ||
@@ -260,6 +262,7 @@ // 2. should return stale cache before wait period has finished | ||
const rejectionSpy = _sinon2.default.spy(() => Promise.reject(new Error('an error occurred'))); | ||
(0, _expect2.default)(cacheInstance.waiting.get(dummyKey)).to.be.a('undefined'); | ||
const info = cacheInstance.debug(); | ||
(0, _expect2.default)(info.waiting.get(dummyKey)).to.be.a('undefined'); | ||
return cacheInstance.get(dummyKey, { worker: rejectionSpy }).then(obj => { | ||
(0, _expect2.default)(rejectionSpy.called).to.equal(true); | ||
(0, _expect2.default)(cacheInstance.waiting.get(dummyKey)).not.to.equal(0); | ||
(0, _expect2.default)(info.waiting.get(dummyKey)).not.to.equal(0); | ||
(0, _expect2.default)(obj.value).to.eql(cacheValue); | ||
@@ -325,3 +328,4 @@ (0, _expect2.default)(obj.cache).to.equal('stale'); | ||
cacheInstance.set('N/A', 'hei verden'); | ||
cacheInstance.waiting.delete('N/A'); | ||
const info = cacheInstance.debug(); | ||
info.waiting.delete('N/A'); | ||
setTimeout(() => { | ||
@@ -344,12 +348,13 @@ return cacheInstance.get('N/A', _extends({}, conf, { worker: rejectionSpy })).then(obj => { | ||
}; | ||
(0, _expect2.default)(cacheInstance.waiting.get('N/A')).to.be.a('undefined'); | ||
const info = cacheInstance.debug(); | ||
(0, _expect2.default)(info.waiting.get('N/A')).to.be.a('undefined'); | ||
cacheInstance.get('N/A', _extends({}, conf, { worker: rejectionSpy })).catch(err => { | ||
(0, _expect2.default)(err).to.be.an(Error); | ||
(0, _expect2.default)(rejectionSpy.callCount).to.equal(1); | ||
(0, _expect2.default)(cacheInstance.waiting.get('N/A').wait).to.equal(10); | ||
const { started } = cacheInstance.waiting.get('N/A'); | ||
(0, _expect2.default)(info.waiting.get('N/A').wait).to.equal(10); | ||
const { started } = info.waiting.get('N/A'); | ||
cacheInstance.get('N/A', _extends({}, conf, { worker: rejectionSpy })).catch(err => { | ||
(0, _expect2.default)(err).to.be.an(Error); | ||
(0, _expect2.default)(rejectionSpy.callCount).to.equal(1); | ||
(0, _expect2.default)(cacheInstance.waiting.get('N/A')).to.eql({ | ||
(0, _expect2.default)(info.waiting.get('N/A')).to.eql({ | ||
started, | ||
@@ -363,4 +368,4 @@ wait: 10, | ||
(0, _expect2.default)(rejectionSpy.callCount).to.equal(2); | ||
(0, _expect2.default)(cacheInstance.waiting.get('N/A').wait).to.equal(10); | ||
(0, _expect2.default)(cacheInstance.waiting.get('N/A').started).not.to.equal(started); | ||
(0, _expect2.default)(info.waiting.get('N/A').wait).to.equal(10); | ||
(0, _expect2.default)(info.waiting.get('N/A').started).not.to.equal(started); | ||
done(); | ||
@@ -367,0 +372,0 @@ }); |
@@ -305,3 +305,4 @@ 'use strict'; | ||
cache, | ||
waiting | ||
waiting, | ||
jobs | ||
})); | ||
@@ -329,5 +330,3 @@ }; | ||
debug, | ||
log, | ||
// for testing purposes | ||
waiting | ||
log | ||
}; | ||
@@ -334,0 +333,0 @@ }; |
@@ -81,3 +81,3 @@ 'use strict'; | ||
Object.keys(mapLoaded).map(key => { | ||
cacheInstance.cache.set((0, _persistenceHelpers.extractKeyFromRedis)(cacheKeyPrefix, key), mapLoaded[key]); | ||
cacheInstance.set((0, _persistenceHelpers.extractKeyFromRedis)(cacheKeyPrefix, key), mapLoaded[key].value, mapLoaded[key].TTL); | ||
return key; | ||
@@ -84,0 +84,0 @@ }); |
@@ -66,3 +66,2 @@ 'use strict'; | ||
const maxAge = 10000; | ||
const waiting = new Map(); | ||
const cache = (0, _lruCache2.default)({ | ||
@@ -79,3 +78,3 @@ max: 100, | ||
cache.set('yo2', entry3); | ||
// omit now field | ||
// omit now and waiting field | ||
const _getCacheInfo = (0, _debug.getCacheInfo)({ | ||
@@ -86,6 +85,6 @@ full: true, | ||
maxAge, | ||
waiting | ||
waiting: new Map() | ||
}), | ||
{ now } = _getCacheInfo, | ||
info = _objectWithoutProperties(_getCacheInfo, ['now']); | ||
{ now, waiting } = _getCacheInfo, | ||
info = _objectWithoutProperties(_getCacheInfo, ['now', 'waiting']); | ||
(0, _expect2.default)(info).to.eql({ | ||
@@ -92,0 +91,0 @@ full: true, |
@@ -33,3 +33,3 @@ 'use strict'; | ||
const ret = {}; | ||
Object.keys(obj).filter(key => !/^log$|^cache$|^waiting$/.test(key)).forEach(key => { | ||
Object.keys(obj).filter(key => !/^log$|^cache$/.test(key)).forEach(key => { | ||
ret[key] = obj[key]; | ||
@@ -36,0 +36,0 @@ }); |
@@ -9,3 +9,3 @@ { | ||
"homepage": "https://github.com/nrkno/nodecache-as-promised#readme", | ||
"version": "1.0.4", | ||
"version": "1.0.5", | ||
"description": "NodeJs in-memory cache with Promise support. Extendable with middlewares. Middlewares provided: Distributed invalidation and persistence of cache misses", | ||
@@ -12,0 +12,0 @@ "main": "lib/index.js", |
@@ -185,6 +185,7 @@ /* eslint max-nested-callbacks: 0 */ | ||
})) | ||
expect(cacheInstance.waiting.get(dummyKey)).to.be.a('undefined') | ||
const info = cacheInstance.debug() | ||
expect(info.waiting.get(dummyKey)).to.be.a('undefined') | ||
return cacheInstance.get(dummyKey, { workerTimeout: 0, worker: timeoutSpy }).then((obj) => { | ||
expect(timeoutSpy.called).to.equal(true) | ||
expect(cacheInstance.waiting.get(dummyKey)).not.to.equal(0) | ||
expect(info.waiting.get(dummyKey)).not.to.equal(0) | ||
expect(obj.value).to.eql(cacheValue) | ||
@@ -218,3 +219,4 @@ expect(obj.cache).to.equal('stale') | ||
expect(obj.value).to.eql(cacheValue) | ||
expect(cacheInstance.waiting.get(dummyKey).wait).to.equal(10) | ||
const info = cacheInstance.debug() | ||
expect(info.waiting.get(dummyKey).wait).to.equal(10) | ||
return cacheInstance.get(dummyKey, {...conf, worker: resolveSpy}).then((obj) => { | ||
@@ -247,6 +249,7 @@ // 2. should return stale cache before wait period has finished | ||
const rejectionSpy = sinon.spy(() => Promise.reject(new Error('an error occurred'))) | ||
expect(cacheInstance.waiting.get(dummyKey)).to.be.a('undefined') | ||
const info = cacheInstance.debug() | ||
expect(info.waiting.get(dummyKey)).to.be.a('undefined') | ||
return cacheInstance.get(dummyKey, {worker: rejectionSpy}).then((obj) => { | ||
expect(rejectionSpy.called).to.equal(true) | ||
expect(cacheInstance.waiting.get(dummyKey)).not.to.equal(0) | ||
expect(info.waiting.get(dummyKey)).not.to.equal(0) | ||
expect(obj.value).to.eql(cacheValue) | ||
@@ -312,3 +315,4 @@ expect(obj.cache).to.equal('stale') | ||
cacheInstance.set('N/A', 'hei verden') | ||
cacheInstance.waiting.delete('N/A') | ||
const info = cacheInstance.debug() | ||
info.waiting.delete('N/A') | ||
setTimeout(() => { | ||
@@ -331,12 +335,13 @@ return cacheInstance.get('N/A', {...conf, worker: rejectionSpy}).then((obj) => { | ||
} | ||
expect(cacheInstance.waiting.get('N/A')).to.be.a('undefined') | ||
const info = cacheInstance.debug() | ||
expect(info.waiting.get('N/A')).to.be.a('undefined') | ||
cacheInstance.get('N/A', {...conf, worker: rejectionSpy}).catch((err) => { | ||
expect(err).to.be.an(Error) | ||
expect(rejectionSpy.callCount).to.equal(1) | ||
expect(cacheInstance.waiting.get('N/A').wait).to.equal(10) | ||
const {started} = cacheInstance.waiting.get('N/A') | ||
expect(info.waiting.get('N/A').wait).to.equal(10) | ||
const {started} = info.waiting.get('N/A') | ||
cacheInstance.get('N/A', {...conf, worker: rejectionSpy}).catch((err) => { | ||
expect(err).to.be.an(Error) | ||
expect(rejectionSpy.callCount).to.equal(1) | ||
expect(cacheInstance.waiting.get('N/A')).to.eql({ | ||
expect(info.waiting.get('N/A')).to.eql({ | ||
started, | ||
@@ -350,4 +355,4 @@ wait: 10, | ||
expect(rejectionSpy.callCount).to.equal(2) | ||
expect(cacheInstance.waiting.get('N/A').wait).to.equal(10) | ||
expect(cacheInstance.waiting.get('N/A').started).not.to.equal(started) | ||
expect(info.waiting.get('N/A').wait).to.equal(10) | ||
expect(info.waiting.get('N/A').started).not.to.equal(started) | ||
done() | ||
@@ -354,0 +359,0 @@ }) |
@@ -295,3 +295,4 @@ /** | ||
cache, | ||
waiting | ||
waiting, | ||
jobs | ||
}) | ||
@@ -319,5 +320,3 @@ } | ||
debug, | ||
log, | ||
// for testing purposes | ||
waiting | ||
log | ||
} | ||
@@ -324,0 +323,0 @@ } |
@@ -77,3 +77,3 @@ /** | ||
Object.keys(mapLoaded).map((key) => { | ||
cacheInstance.cache.set(extractKeyFromRedis(cacheKeyPrefix, key), mapLoaded[key]) | ||
cacheInstance.set(extractKeyFromRedis(cacheKeyPrefix, key), mapLoaded[key].value, mapLoaded[key].TTL) | ||
return key | ||
@@ -80,0 +80,0 @@ }) |
@@ -57,3 +57,2 @@ import { | ||
const maxAge = 10000 | ||
const waiting = new Map() | ||
const cache = lruCache({ | ||
@@ -70,4 +69,4 @@ max: 100, | ||
cache.set('yo2', entry3) | ||
// omit now field | ||
const {now, ...info} = getCacheInfo({ | ||
// omit now and waiting field | ||
const {now, waiting, ...info} = getCacheInfo({ | ||
full: true, | ||
@@ -77,3 +76,3 @@ search: 'yo*', | ||
maxAge, | ||
waiting | ||
waiting: new Map() | ||
}) | ||
@@ -80,0 +79,0 @@ expect(info).to.eql({ |
@@ -30,3 +30,3 @@ /** | ||
Object.keys(obj) | ||
.filter((key) => !/^log$|^cache$|^waiting$/.test(key)) | ||
.filter((key) => !/^log$|^cache$/.test(key)) | ||
.forEach((key) => { | ||
@@ -33,0 +33,0 @@ ret[key] = obj[key] |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
609936
4273