lru-cache
Advanced tools
Comparing version 7.10.3 to 7.11.0
@@ -65,2 +65,6 @@ // Type definitions for lru-cache 7.10.0 | ||
/** | ||
* @since 7.11.0 | ||
*/ | ||
public readonly noDeleteOnStaleGet: boolean | ||
/** | ||
* @since 7.6.0 | ||
@@ -421,2 +425,12 @@ */ | ||
/** | ||
* Do not delete stale items when they are retrieved with cache.get() | ||
* Note that the get() return value will still be `undefined` unless | ||
* allowStale is true. | ||
* | ||
* @default false | ||
* @since 7.11.0 | ||
*/ | ||
noDeleteOnStaleGet?: boolean | ||
/** | ||
* Update the age of items on cache.has(), renewing their TTL | ||
@@ -525,2 +539,3 @@ * | ||
updateAgeOnGet?: boolean | ||
noDeleteOnStaleGet?: boolean | ||
} | ||
@@ -545,2 +560,3 @@ | ||
updateAgeOnGet?: boolean | ||
noDeleteOnStaleGet?: boolean | ||
size?: number | ||
@@ -547,0 +563,0 @@ sizeCalculation?: SizeCalculator<K, V> |
11
index.js
@@ -163,2 +163,3 @@ const perf = | ||
noDeleteOnFetchRejection, | ||
noDeleteOnStaleGet, | ||
} = options | ||
@@ -236,2 +237,3 @@ | ||
this.allowStale = !!allowStale || !!stale | ||
this.noDeleteOnStaleGet = !!noDeleteOnStaleGet | ||
this.updateAgeOnGet = !!updateAgeOnGet | ||
@@ -747,2 +749,3 @@ this.updateAgeOnHas = !!updateAgeOnHas | ||
updateAgeOnGet = this.updateAgeOnGet, | ||
noDeleteOnStaleGet = this.noDeleteOnStaleGet, | ||
// set options | ||
@@ -759,3 +762,3 @@ ttl = this.ttl, | ||
if (!this.fetchMethod) { | ||
return this.get(k, { allowStale, updateAgeOnGet }) | ||
return this.get(k, { allowStale, updateAgeOnGet, noDeleteOnStaleGet }) | ||
} | ||
@@ -766,2 +769,3 @@ | ||
updateAgeOnGet, | ||
noDeleteOnStaleGet, | ||
ttl, | ||
@@ -810,2 +814,3 @@ noDisposeOnSet, | ||
updateAgeOnGet = this.updateAgeOnGet, | ||
noDeleteOnStaleGet = this.noDeleteOnStaleGet, | ||
} = {} | ||
@@ -820,3 +825,5 @@ ) { | ||
if (!fetching) { | ||
this.delete(k) | ||
if (!noDeleteOnStaleGet) { | ||
this.delete(k) | ||
} | ||
return allowStale ? value : undefined | ||
@@ -823,0 +830,0 @@ } else { |
{ | ||
"name": "lru-cache", | ||
"description": "A cache object that deletes the least-recently-used items.", | ||
"version": "7.10.3", | ||
"version": "7.11.0", | ||
"author": "Isaac Z. Schlueter <i@izs.me>", | ||
@@ -6,0 +6,0 @@ "keywords": [ |
@@ -342,2 +342,18 @@ # lru-cache | ||
### `noDeleteOnStaleGet` | ||
When using time-expiring entries with `ttl`, by default stale | ||
items will be removed from the cache when the key is accessed | ||
with `cache.get()`. | ||
Setting `noDeleteOnStaleGet` to `true` will cause stale items to | ||
remain in the cache, until they are explicitly deleted with | ||
`cache.delete(key)`, or retrieved with `noDeleteOnStaleGet` set | ||
to `false`. | ||
This may be overridden by passing an options object to | ||
`cache.get()`. | ||
Boolean, default false, only relevant if `ttl` is set. | ||
### `updateAgeOnGet` | ||
@@ -344,0 +360,0 @@ |
71433
1418
802