lru-cache
Advanced tools
Comparing version 10.0.3 to 10.1.0
@@ -17,2 +17,3 @@ /** | ||
export type { ZeroArray }; | ||
export type { Stack }; | ||
export type StackLike = Stack | Index[]; | ||
@@ -30,3 +31,2 @@ declare class Stack { | ||
} | ||
export type { Stack }; | ||
/** | ||
@@ -561,3 +561,4 @@ * Promise representing an in-progress {@link LRUCache#fetch} call | ||
/** | ||
* Entry objects used by {@link LRUCache#load} and {@link LRUCache#dump} | ||
* Entry objects used by {@link LRUCache#load} and {@link LRUCache#dump}, | ||
* and returned by {@link LRUCache#info}. | ||
*/ | ||
@@ -771,2 +772,9 @@ interface Entry<V> { | ||
/** | ||
* Get the extended info about a given entry, to get its value, size, and | ||
* TTL info simultaneously. Like {@link LRUCache#dump}, but just for a | ||
* single key. Always returns stale values, if their info is found in the | ||
* cache, so be sure to check for expired TTLs if relevant. | ||
*/ | ||
info(key: K): LRUCache.Entry<V> | undefined; | ||
/** | ||
* Return an array of [key, {@link LRUCache.Entry}] tuples which can be | ||
@@ -773,0 +781,0 @@ * passed to cache.load() |
@@ -740,2 +740,33 @@ "use strict"; | ||
/** | ||
* Get the extended info about a given entry, to get its value, size, and | ||
* TTL info simultaneously. Like {@link LRUCache#dump}, but just for a | ||
* single key. Always returns stale values, if their info is found in the | ||
* cache, so be sure to check for expired TTLs if relevant. | ||
*/ | ||
info(key) { | ||
const i = this.#keyMap.get(key); | ||
if (i === undefined) | ||
return undefined; | ||
const v = this.#valList[i]; | ||
const value = this.#isBackgroundFetch(v) | ||
? v.__staleWhileFetching | ||
: v; | ||
if (value === undefined) | ||
return undefined; | ||
const entry = { value }; | ||
if (this.#ttls && this.#starts) { | ||
const ttl = this.#ttls[i]; | ||
const start = this.#starts[i]; | ||
if (ttl && start) { | ||
const remain = ttl - (perf.now() - start); | ||
entry.ttl = remain; | ||
entry.start = Date.now(); | ||
} | ||
} | ||
if (this.#sizes) { | ||
entry.size = this.#sizes[i]; | ||
} | ||
return entry; | ||
} | ||
/** | ||
* Return an array of [key, {@link LRUCache.Entry}] tuples which can be | ||
@@ -742,0 +773,0 @@ * passed to cache.load() |
@@ -17,2 +17,3 @@ /** | ||
export type { ZeroArray }; | ||
export type { Stack }; | ||
export type StackLike = Stack | Index[]; | ||
@@ -30,3 +31,2 @@ declare class Stack { | ||
} | ||
export type { Stack }; | ||
/** | ||
@@ -561,3 +561,4 @@ * Promise representing an in-progress {@link LRUCache#fetch} call | ||
/** | ||
* Entry objects used by {@link LRUCache#load} and {@link LRUCache#dump} | ||
* Entry objects used by {@link LRUCache#load} and {@link LRUCache#dump}, | ||
* and returned by {@link LRUCache#info}. | ||
*/ | ||
@@ -771,2 +772,9 @@ interface Entry<V> { | ||
/** | ||
* Get the extended info about a given entry, to get its value, size, and | ||
* TTL info simultaneously. Like {@link LRUCache#dump}, but just for a | ||
* single key. Always returns stale values, if their info is found in the | ||
* cache, so be sure to check for expired TTLs if relevant. | ||
*/ | ||
info(key: K): LRUCache.Entry<V> | undefined; | ||
/** | ||
* Return an array of [key, {@link LRUCache.Entry}] tuples which can be | ||
@@ -773,0 +781,0 @@ * passed to cache.load() |
@@ -737,2 +737,33 @@ /** | ||
/** | ||
* Get the extended info about a given entry, to get its value, size, and | ||
* TTL info simultaneously. Like {@link LRUCache#dump}, but just for a | ||
* single key. Always returns stale values, if their info is found in the | ||
* cache, so be sure to check for expired TTLs if relevant. | ||
*/ | ||
info(key) { | ||
const i = this.#keyMap.get(key); | ||
if (i === undefined) | ||
return undefined; | ||
const v = this.#valList[i]; | ||
const value = this.#isBackgroundFetch(v) | ||
? v.__staleWhileFetching | ||
: v; | ||
if (value === undefined) | ||
return undefined; | ||
const entry = { value }; | ||
if (this.#ttls && this.#starts) { | ||
const ttl = this.#ttls[i]; | ||
const start = this.#starts[i]; | ||
if (ttl && start) { | ||
const remain = ttl - (perf.now() - start); | ||
entry.ttl = remain; | ||
entry.start = Date.now(); | ||
} | ||
} | ||
if (this.#sizes) { | ||
entry.size = this.#sizes[i]; | ||
} | ||
return entry; | ||
} | ||
/** | ||
* Return an array of [key, {@link LRUCache.Entry}] tuples which can be | ||
@@ -739,0 +770,0 @@ * passed to cache.load() |
{ | ||
"name": "lru-cache", | ||
"description": "A cache object that deletes the least-recently-used items.", | ||
"version": "10.0.3", | ||
"version": "10.1.0", | ||
"author": "Isaac Z. Schlueter <i@izs.me>", | ||
@@ -6,0 +6,0 @@ "keywords": [ |
@@ -610,2 +610,17 @@ # lru-cache | ||
### `info(key) => Entry | undefined` | ||
Return an `Entry` object containing the currently cached value, | ||
as well as ttl and size information if available. Returns | ||
undefined if the key is not found in the cache. | ||
Unlike `dump()` (which is designed to be portable and survive | ||
serialization), the `start` value is always the current | ||
timestamp, and the `ttl` is a calculated remaining time to live | ||
(negative if expired). | ||
Note that stale values are always returned, rather than being | ||
pruned and treated as if they were not in the cache. If you wish | ||
to exclude stale entries, guard against a negative `ttl` value. | ||
### `async fetch(key, options = {}) => Promise` | ||
@@ -612,0 +627,0 @@ |
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
456410
4582
1205