@nrk/nodecache-as-promised
Advanced tools
Comparing version 1.0.8 to 1.0.9
@@ -116,3 +116,3 @@ 'use strict'; | ||
const set = (key, value, ttl = DEFAULT_CACHE_EXPIRE) => { | ||
cache.set(key, _extends({}, (0, _cacheHelpers.createEntry)(value, ttl), { cache: CACHE_HIT })); | ||
cache.set(key, _extends({}, (0, _cacheHelpers.createEntry)(value, ttl), { cache: CACHE_HIT }), maxAge); | ||
}; | ||
@@ -198,3 +198,3 @@ | ||
return Promise.resolve(obj); | ||
} else if (obj && (!worker || (0, _cacheHelpers.isWaiting)(waiting.get(key)))) { | ||
} else if (obj && (0, _cacheHelpers.isWaiting)(waiting.get(key))) { | ||
return Promise.resolve(_extends({}, obj, { cache: CACHE_STALE })); | ||
@@ -279,3 +279,2 @@ } else if ((0, _cacheHelpers.isWaiting)(waiting.get(key))) { | ||
return new Map(keys().reduce((acc, key, i) => { | ||
// console.log({[key]: vals[i]}) | ||
acc.push([key, vals[i]]); | ||
@@ -282,0 +281,0 @@ return acc; |
@@ -32,24 +32,2 @@ 'use strict'; | ||
/* | ||
export const existsAndNotStale = (entry, wait, nowDefault) => { | ||
const now = nowDefault || Date.now() | ||
let remainingToWait = 0 | ||
if (wait) { | ||
remainingToWait = wait.started + wait.wait - now | ||
} | ||
if (remainingToWait > 0) { | ||
return true | ||
} | ||
if (entry) { | ||
return entry.created + entry.TTL > now | ||
} | ||
return false | ||
} | ||
export const finishedWaiting = (waiting) => { | ||
return waiting ? waiting.waitUntil < Date.now() : true | ||
} | ||
*/ | ||
const waitingForError = exports.waitingForError = (key, wait = {}) => { | ||
@@ -56,0 +34,0 @@ return new Error(`Waiting for next run for ${key}, wait: ${JSON.stringify(wait, null, 2)}`); |
@@ -9,3 +9,3 @@ { | ||
"homepage": "https://github.com/nrkno/nodecache-as-promised#readme", | ||
"version": "1.0.8", | ||
"version": "1.0.9", | ||
"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", |
@@ -101,3 +101,3 @@ /** | ||
const set = (key, value, ttl = DEFAULT_CACHE_EXPIRE) => { | ||
cache.set(key, {...createEntry(value, ttl), cache: CACHE_HIT}) | ||
cache.set(key, {...createEntry(value, ttl), cache: CACHE_HIT}, maxAge) | ||
} | ||
@@ -185,3 +185,3 @@ | ||
return Promise.resolve(obj) | ||
} else if (obj && (!worker || isWaiting(waiting.get(key)))) { | ||
} else if (obj && isWaiting(waiting.get(key))) { | ||
return Promise.resolve({...obj, cache: CACHE_STALE}) | ||
@@ -266,3 +266,2 @@ } else if (isWaiting(waiting.get(key))) { | ||
return new Map(keys().reduce((acc, key, i) => { | ||
// console.log({[key]: vals[i]}) | ||
acc.push([key, vals[i]]) | ||
@@ -269,0 +268,0 @@ return acc |
@@ -32,24 +32,2 @@ /** | ||
/* | ||
export const existsAndNotStale = (entry, wait, nowDefault) => { | ||
const now = nowDefault || Date.now() | ||
let remainingToWait = 0 | ||
if (wait) { | ||
remainingToWait = wait.started + wait.wait - now | ||
} | ||
if (remainingToWait > 0) { | ||
return true | ||
} | ||
if (entry) { | ||
return entry.created + entry.TTL > now | ||
} | ||
return false | ||
} | ||
export const finishedWaiting = (waiting) => { | ||
return waiting ? waiting.waitUntil < Date.now() : true | ||
} | ||
*/ | ||
export const waitingForError = (key, wait = {}) => { | ||
@@ -56,0 +34,0 @@ return new Error(`Waiting for next run for ${key}, wait: ${JSON.stringify(wait, null, 2)}`) |
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
619612
4361