Modules | @vltpkg/cache
Classes
Cache
Extends
LRUCache
<string
,Buffer
,CacheFetchContext
>
Constructors
new Cache()
Parameters
• options: CacheOptions
Returns
Overrides
`LRUCache< string, Buffer, CacheFetchContext
.constructor`
Defined in
src/cache/src/index.ts:95
Properties
[toStringTag]
Overrides
LRUCache.[toStringTag]
Defined in
src/cache/src/index.ts:64
allowStale
LRUCache.OptionsBase.allowStale
Inherited from
LRUCache.allowStale
Defined in
node_modules/.pnpm/[email protected]/node_modules/lru-cache/dist/esm/index.d.ts:865
allowStaleOnFetchAbort
LRUCache.OptionsBase.allowStaleOnFetchAbort
Inherited from
LRUCache.allowStaleOnFetchAbort
Defined in
node_modules/.pnpm/[email protected]/node_modules/lru-cache/dist/esm/index.d.ts:893
allowStaleOnFetchRejection
LRUCache.OptionsBase.allowStaleOnFetchRejection
Inherited from
LRUCache.allowStaleOnFetchRejection
Defined in
node_modules/.pnpm/[email protected]/node_modules/lru-cache/dist/esm/index.d.ts:897
ignoreFetchAbort
LRUCache.OptionsBase.ignoreFetchAbort
Inherited from
LRUCache.ignoreFetchAbort
Defined in
node_modules/.pnpm/[email protected]/node_modules/lru-cache/dist/esm/index.d.ts:901
maxEntrySize
LRUCache.OptionsBase.maxEntrySize
Inherited from
LRUCache.maxEntrySize
Defined in
node_modules/.pnpm/[email protected]/node_modules/lru-cache/dist/esm/index.d.ts:877
noDeleteOnFetchRejection
LRUCache.OptionsBase.noDeleteOnFetchRejection
Inherited from
LRUCache.noDeleteOnFetchRejection
Defined in
node_modules/.pnpm/[email protected]/node_modules/lru-cache/dist/esm/index.d.ts:885
noDeleteOnStaleGet
LRUCache.OptionsBase.noDeleteOnStaleGet
Inherited from
LRUCache.noDeleteOnStaleGet
Defined in
node_modules/.pnpm/[email protected]/node_modules/lru-cache/dist/esm/index.d.ts:889
noDisposeOnSet
LRUCache.OptionsBase.noDisposeOnSet
Inherited from
LRUCache.noDisposeOnSet
Defined in
node_modules/.pnpm/[email protected]/node_modules/lru-cache/dist/esm/index.d.ts:869
noUpdateTTL
LRUCache.OptionsBase.noUpdateTTL
Inherited from
LRUCache.noUpdateTTL
Defined in
node_modules/.pnpm/[email protected]/node_modules/lru-cache/dist/esm/index.d.ts:873
onDiskDelete()?
Parameters
• path: string
• key: string
• deleted: boolean
Returns
any
Defined in
src/cache/src/index.ts:69
onDiskWrite()?
Parameters
• path: string
• key: string
• data: Buffer
Returns
any
Defined in
src/cache/src/index.ts:68
sizeCalculation?
LRUCache.OptionsBase.sizeCalculation
Inherited from
LRUCache.sizeCalculation
Defined in
node_modules/.pnpm/[email protected]/node_modules/lru-cache/dist/esm/index.d.ts:881
ttl
Inherited from
LRUCache.ttl
Defined in
node_modules/.pnpm/[email protected]/node_modules/lru-cache/dist/esm/index.d.ts:845
ttlAutopurge
LRUCache.OptionsBase.ttlAutopurge
Inherited from
LRUCache.ttlAutopurge
Defined in
node_modules/.pnpm/[email protected]/node_modules/lru-cache/dist/esm/index.d.ts:853
ttlResolution
LRUCache.OptionsBase.ttlResolution
Inherited from
LRUCache.ttlResolution
Defined in
node_modules/.pnpm/[email protected]/node_modules/lru-cache/dist/esm/index.d.ts:849
updateAgeOnGet
LRUCache.OptionsBase.updateAgeOnGet
Inherited from
LRUCache.updateAgeOnGet
Defined in
node_modules/.pnpm/[email protected]/node_modules/lru-cache/dist/esm/index.d.ts:857
updateAgeOnHas
LRUCache.OptionsBase.updateAgeOnHas
Inherited from
LRUCache.updateAgeOnHas
Defined in
node_modules/.pnpm/[email protected]/node_modules/lru-cache/dist/esm/index.d.ts:861
Accessors
calculatedSize
The total computed size of items in the cache (read-only)
Returns
number
Inherited from
LRUCache.calculatedSize
Defined in
node_modules/.pnpm/[email protected]/node_modules/lru-cache/dist/esm/index.d.ts:945
dispose
LRUCache.OptionsBase.dispose (read-only)
Returns
Inherited from
LRUCache.dispose
Defined in
node_modules/.pnpm/[email protected]/node_modules/lru-cache/dist/esm/index.d.ts:958
disposeAfter
LRUCache.OptionsBase.disposeAfter (read-only)
Returns
Inherited from
LRUCache.disposeAfter
Defined in
node_modules/.pnpm/[email protected]/node_modules/lru-cache/dist/esm/index.d.ts:962
fetchMethod
LRUCache.OptionsBase.fetchMethod (read-only)
Returns
Inherited from
LRUCache.fetchMethod
Defined in
node_modules/.pnpm/[email protected]/node_modules/lru-cache/dist/esm/index.d.ts:953
max
LRUCache.OptionsBase.max (read-only)
Returns
number
Inherited from
LRUCache.max
Defined in
node_modules/.pnpm/[email protected]/node_modules/lru-cache/dist/esm/index.d.ts:937
maxSize
LRUCache.OptionsBase.maxSize (read-only)
Returns
number
Inherited from
LRUCache.maxSize
Defined in
node_modules/.pnpm/[email protected]/node_modules/lru-cache/dist/esm/index.d.ts:941
memoMethod
Returns
undefined
| Memoizer
<K
, V
, FC
>
Inherited from
LRUCache.memoMethod
Defined in
node_modules/.pnpm/[email protected]/node_modules/lru-cache/dist/esm/index.d.ts:954
pending
A list of the actions currently happening in the background
Returns
Promise
<BooleanOrVoid
>[]
Defined in
src/cache/src/index.ts:83
random
ensure we get a different random key for every write, just in case the same file tries to write multiple times, it’ll still be atomic.
Returns
string
Defined in
src/cache/src/index.ts:76
size
The number of items stored in the cache (read-only)
Returns
number
Inherited from
LRUCache.size
Defined in
node_modules/.pnpm/[email protected]/node_modules/lru-cache/dist/esm/index.d.ts:949
defaultMax
By default, cache up to 1000 items in memory. Disk cache is unbounded.
Returns
number
Defined in
src/cache/src/index.ts:91
Methods
[asyncIterator]()
Returns
AsyncGenerator
<[string
, Buffer
], void
, void
>
Defined in
src/cache/src/index.ts:153
[iterator]()
Returns
Generator
<[string
, Buffer
], void
, unknown
>
Overrides
LRUCache.[iterator]
Defined in
src/cache/src/index.ts:184
clear()
Clear the cache entirely, throwing away all values.
Returns
void
Inherited from
LRUCache.clear
Defined in
node_modules/.pnpm/[email protected]/node_modules/lru-cache/dist/esm/index.d.ts:1275
delete()
Pass true
as second argument to delete not just from the in-memory
cache, but the disk backing as well.
Parameters
• key: string
• fromDisk: boolean
= false
Returns
boolean
Overrides
LRUCache.delete
Defined in
src/cache/src/index.ts:205
dump()
Return an array of [key, LRUCache.Entry] tuples which can be passed to LRUCache#load.
The start
fields are calculated relative to a portable Date.now()
timestamp, even if performance.now()
is available.
Stale entries are always included in the dump
, even if
LRUCache.OptionsBase.allowStale is false.
Note: this returns an actual array, not a generator, so it can be more easily passed around.
Returns
[string
, Entry
<Buffer
>][]
Inherited from
LRUCache.dump
Defined in
node_modules/.pnpm/[email protected]/node_modules/lru-cache/dist/esm/index.d.ts:1069
entries()
Return a generator yielding [key, value]
pairs,
in order from most recently used to least recently used.
Returns
Generator
<[string
, Buffer
], void
, unknown
>
Inherited from
LRUCache.entries
Defined in
node_modules/.pnpm/[email protected]/node_modules/lru-cache/dist/esm/index.d.ts:973
fetch()
fetch(k, fetchOptions)
Make an asynchronous cached fetch using the LRUCache.OptionsBase.fetchMethod function.
If the value is in the cache and not stale, then the returned Promise resolves to the value.
If not in the cache, or beyond its TTL staleness, then
fetchMethod(key, staleValue, { options, signal, context })
is
called, and the value returned will be added to the cache once
resolved.
If called with allowStale
, and an asynchronous fetch is
currently in progress to reload a stale value, then the former
stale value will be returned.
If called with forceRefresh
, then the cached item will be
re-fetched, even if it is not stale. However, if allowStale
is also
set, then the old value will still be returned. This is useful
in cases where you want to force a reload of a cached value. If
a background fetch is already in progress, then forceRefresh
has no effect.
If multiple fetches for the same key are issued, then they will all be coalesced into a single call to fetchMethod.
Note that this means that handling options such as LRUCache.OptionsBase.allowStaleOnFetchAbort, LRUCache.FetchOptions.signal, and LRUCache.OptionsBase.allowStaleOnFetchRejection will be determined by the FIRST fetch() call for a given key.
This is a known (fixable) shortcoming which will be addresed on when someone complains about it, as the fix would involve added complexity and may not be worth the costs for this edge case.
If LRUCache.OptionsBase.fetchMethod is not specified, then this is
effectively an alias for Promise.resolve(cache.get(key))
.
When the fetch method resolves to a value, if the fetch has not been aborted due to deletion, eviction, or being overwritten, then it is added to the cache using the options provided.
If the key is evicted or deleted before the fetchMethod
resolves, then the AbortSignal passed to the fetchMethod
will
receive an abort
event, and the promise returned by fetch()
will reject with the reason for the abort.
If a signal
is passed to the fetch()
call, then aborting the
signal will abort the fetch and cause the fetch()
promise to
reject with the reason provided.
Setting context
If an FC
type is set to a type other than unknown
, void
, or
undefined
in the LRUCache constructor, then all
calls to cache.fetch()
must provide a context
option. If
set to undefined
or void
, then calls to fetch must not
provide a context
option.
The context
param allows you to provide arbitrary data that
might be relevant in the course of fetching the data. It is only
relevant for the course of a single fetch()
operation, and
discarded afterwards.
Note: fetch()
calls are inflight-unique
If you call fetch()
multiple times with the same key value,
then every call after the first will resolve on the same
promise1,
even if they have different settings that would otherwise change
the behavior of the fetch, such as noDeleteOnFetchRejection
or ignoreFetchAbort
.
In most cases, this is not a problem (in fact, only fetching something once is what you probably want, if you’re caching in the first place). If you are changing the fetch() options dramatically between runs, there’s a good chance that you might be trying to fit divergent semantics into a single object, and would be better off with multiple cache instances.
1: Ie, they’re not the “same Promise”, but they resolve at the same time, because they’re both waiting on the same underlying fetchMethod response.
Parameters
• k: string
• fetchOptions: FetchOptionsNoContext
<string
, Buffer
> | FetchOptionsWithContext
<string
, Buffer
, object
>
Returns
Promise
<undefined
| Buffer
>
Inherited from
LRUCache.fetch
Defined in
node_modules/.pnpm/[email protected]/node_modules/lru-cache/dist/esm/index.d.ts:1226
fetch(k, fetchOptions)
Parameters
• k: string
• fetchOptions?: FetchOptionsNoContext
<string
, Buffer
>
Returns
Promise
<undefined
| Buffer
>
Inherited from
LRUCache.fetch
Defined in
node_modules/.pnpm/[email protected]/node_modules/lru-cache/dist/esm/index.d.ts:1227
fetchSync()
Read synchronously from the fs cache storage if not already in memory.
Parameters
• key: string
• opts?: FetchOptions
<string
, Buffer
, CacheFetchContext
>
Returns
undefined
| Buffer
Defined in
src/cache/src/index.ts:302
find()
Find a value for which the supplied fn method returns a truthy value,
similar to Array.find()
. fn is called as fn(value, key, cache)
.
Parameters
• fn
• getOptions?: GetOptions
<string
, Buffer
, CacheFetchContext
>
Returns
undefined
| Buffer
Inherited from
LRUCache.find
Defined in
node_modules/.pnpm/[email protected]/node_modules/lru-cache/dist/esm/index.d.ts:1020
forceFetch()
forceFetch(k, fetchOptions)
In some cases, cache.fetch()
may resolve to undefined
, either because
a LRUCache.OptionsBase#fetchMethod was not provided (turning
cache.fetch(k)
into just an async wrapper around cache.get(k)
) or
because ignoreFetchAbort
was specified (either to the constructor or
in the LRUCache.FetchOptions). Also, the
LRUCache.OptionsBase.fetchMethod may return undefined
or void
, making
the test even more complicated.
Because inferring the cases where undefined
might be returned are so
cumbersome, but testing for undefined
can also be annoying, this method
can be used, which will reject if this.fetch()
resolves to undefined.
Parameters
• k: string
• fetchOptions: FetchOptionsNoContext
<string
, Buffer
> | FetchOptionsWithContext
<string
, Buffer
, object
>
Returns
Promise
<Buffer
>
Inherited from
LRUCache.forceFetch
Defined in
node_modules/.pnpm/[email protected]/node_modules/lru-cache/dist/esm/index.d.ts:1241
forceFetch(k, fetchOptions)
Parameters
• k: string
• fetchOptions?: FetchOptionsNoContext
<string
, Buffer
>
Returns
Promise
<Buffer
>
Inherited from
LRUCache.forceFetch
Defined in
node_modules/.pnpm/[email protected]/node_modules/lru-cache/dist/esm/index.d.ts:1242
forEach()
Call the supplied function on each item in the cache, in order from most recently used to least recently used.
fn
is called as fn(value, key, cache)
.
If thisp
is provided, function will be called in the this
-context of
the provided object, or the cache if no thisp
object is provided.
Does not update age or recenty of use, or iterate over stale values.
Parameters
• fn
• thisp?: any
Returns
void
Inherited from
LRUCache.forEach
Defined in
node_modules/.pnpm/[email protected]/node_modules/lru-cache/dist/esm/index.d.ts:1032
get()
Return a value from the cache. Will update the recency of the cache entry found.
If the key is not found, get() will return undefined
.
Parameters
• k: string
• getOptions?: GetOptions
<string
, Buffer
, CacheFetchContext
>
Returns
undefined
| Buffer
Inherited from
LRUCache.get
Defined in
node_modules/.pnpm/[email protected]/node_modules/lru-cache/dist/esm/index.d.ts:1265
getRemainingTTL()
Return the number of ms left in the item’s TTL. If item is not in cache,
returns 0
. Returns Infinity
if item is in cache without a defined TTL.
Parameters
• key: string
Returns
number
Inherited from
LRUCache.getRemainingTTL
Defined in
node_modules/.pnpm/[email protected]/node_modules/lru-cache/dist/esm/index.d.ts:968
has()
Check if a key is in the cache, without updating the recency of use. Will return false if the item is stale, even though it is technically in the cache.
Check if a key is in the cache, without updating the recency of
use. Age is updated if LRUCache.OptionsBase.updateAgeOnHas is set
to true
in either the options or the constructor.
Will return false
if the item is stale, even though it is technically in
the cache. The difference can be determined (if it matters) by using a
status
argument, and inspecting the has
field.
Will not update item age unless LRUCache.OptionsBase.updateAgeOnHas is set.
Parameters
• k: string
• hasOptions?: HasOptions
<string
, Buffer
, CacheFetchContext
>
Returns
boolean
Inherited from
LRUCache.has
Defined in
node_modules/.pnpm/[email protected]/node_modules/lru-cache/dist/esm/index.d.ts:1132
info()
Get the extended info about a given entry, to get its value, size, and
TTL info simultaneously. Returns undefined
if the key is not present.
Unlike LRUCache#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).
Always returns stale values, if their info is found in the cache, so be sure to check for expirations (ie, a negative LRUCache.Entry#ttl) if relevant.
Parameters
• key: string
Returns
undefined
| Entry
<Buffer
>
Inherited from
LRUCache.info
Defined in
node_modules/.pnpm/[email protected]/node_modules/lru-cache/dist/esm/index.d.ts:1055
integrityPath()
given an SRI sha512 integrity string, get the path on disk that is hard-linked to the value.
Parameters
• integrity?: `sha512-${string}`
Returns
undefined
| string
Defined in
src/cache/src/index.ts:284
keys()
Return a generator yielding the keys in the cache, in order from most recently used to least recently used.
Returns
Generator
<string
, void
, unknown
>
Inherited from
LRUCache.keys
Defined in
node_modules/.pnpm/[email protected]/node_modules/lru-cache/dist/esm/index.d.ts:985
load()
Reset the cache and load in the items in entries in the order listed.
The shape of the resulting cache may be different if the same options are not used in both caches.
The start
fields are assumed to be calculated relative to a portable
Date.now()
timestamp, even if performance.now()
is available.
Parameters
• arr: [string
, Entry
<Buffer
>][]
Returns
void
Inherited from
LRUCache.load
Defined in
node_modules/.pnpm/[email protected]/node_modules/lru-cache/dist/esm/index.d.ts:1079
memo()
memo(k, memoOptions)
If the key is found in the cache, then this is equivalent to LRUCache#get. If not, in the cache, then calculate the value using the LRUCache.OptionsBase.memoMethod, and add it to the cache.
If an FC
type is set to a type other than unknown
, void
, or
undefined
in the LRUCache constructor, then all calls to cache.memo()
must provide a context
option. If set to undefined
or void
, then
calls to memo must not provide a context
option.
The context
param allows you to provide arbitrary data that might be
relevant in the course of fetching the data. It is only relevant for the
course of a single memo()
operation, and discarded afterwards.
Parameters
• k: string
• memoOptions: MemoOptionsNoContext
<string
, Buffer
> | MemoOptionsWithContext
<string
, Buffer
, object
>
Returns
Buffer
Inherited from
LRUCache.memo
Defined in
node_modules/.pnpm/[email protected]/node_modules/lru-cache/dist/esm/index.d.ts:1257
memo(k, memoOptions)
Parameters
• k: string
• memoOptions?: MemoOptionsNoContext
<string
, Buffer
>
Returns
Buffer
Inherited from
LRUCache.memo
Defined in
node_modules/.pnpm/[email protected]/node_modules/lru-cache/dist/esm/index.d.ts:1258
path()
given a key, figure out the path on disk where it lives
Parameters
• key: string
Returns
string
Defined in
src/cache/src/index.ts:277
peek()
Like LRUCache#get but doesn’t update recency or delete stale items.
Returns undefined
if the item is stale, unless
LRUCache.OptionsBase.allowStale is set.
Parameters
• k: string
• peekOptions?: PeekOptions
<string
, Buffer
, CacheFetchContext
>
Returns
undefined
| Buffer
Inherited from
LRUCache.peek
Defined in
node_modules/.pnpm/[email protected]/node_modules/lru-cache/dist/esm/index.d.ts:1140
pop()
Evict the least recently used item, returning its value or
undefined
if cache is empty.
Returns
undefined
| Buffer
Inherited from
LRUCache.pop
Defined in
node_modules/.pnpm/[email protected]/node_modules/lru-cache/dist/esm/index.d.ts:1115
promise()
Resolves when there are no pending writes to the disk cache
Returns
Promise
<void
>
Defined in
src/cache/src/index.ts:268
purgeStale()
Delete any stale entries. Returns true if anything was removed, false otherwise.
Returns
boolean
Inherited from
LRUCache.purgeStale
Defined in
node_modules/.pnpm/[email protected]/node_modules/lru-cache/dist/esm/index.d.ts:1042
rentries()
Inverse order version of LRUCache.entries
Return a generator yielding [key, value]
pairs,
in order from least recently used to most recently used.
Returns
Generator
<(string
| Buffer
)[], void
, unknown
>
Inherited from
LRUCache.rentries
Defined in
node_modules/.pnpm/[email protected]/node_modules/lru-cache/dist/esm/index.d.ts:980
rforEach()
The same as LRUCache.forEach but items are iterated over in reverse order. (ie, less recently used items are iterated over first.)
Parameters
• fn
• thisp?: any
Returns
void
Inherited from
LRUCache.rforEach
Defined in
node_modules/.pnpm/[email protected]/node_modules/lru-cache/dist/esm/index.d.ts:1037
rkeys()
Inverse order version of LRUCache.keys
Return a generator yielding the keys in the cache, in order from least recently used to most recently used.
Returns
Generator
<string
, void
, unknown
>
Inherited from
LRUCache.rkeys
Defined in
node_modules/.pnpm/[email protected]/node_modules/lru-cache/dist/esm/index.d.ts:992
rvalues()
Inverse order version of LRUCache.values
Return a generator yielding the values in the cache, in order from least recently used to most recently used.
Returns
Generator
<undefined
| Buffer
, void
, unknown
>
Inherited from
LRUCache.rvalues
Defined in
node_modules/.pnpm/[email protected]/node_modules/lru-cache/dist/esm/index.d.ts:1004
set()
Sets an item in the memory cache (like LRUCache.set
), and schedules a
background operation to write it to disk.
Use the CacheOptions#onDiskWrite method to know exactly when this
happens, or await cache.promise()
to defer until all pending actions are
completed.
The noDiskWrite
option can be set to prevent it from writing back to the
disk cache. This is almost never relevant for consumers, and is used
internally to prevent the write at the end of fetch()
from excessively
writing over a file we just read from.
Parameters
• key: string
• val: Buffer
• options?: SetOptions
<string
, Buffer
, CacheFetchContext
> & object
Returns
Overrides
LRUCache.set
Defined in
src/cache/src/index.ts:230
values()
Return a generator yielding the values in the cache, in order from most recently used to least recently used.
Returns
Generator
<Buffer
, void
, unknown
>
Inherited from
LRUCache.values
Defined in
node_modules/.pnpm/[email protected]/node_modules/lru-cache/dist/esm/index.d.ts:997
walk()
Walk over all the items cached to disk (not just in memory). Useful for cleanup, pruning, etc.
Implementation for for await
to walk over entries.
Returns
AsyncGenerator
<[string
, Buffer
], void
, unknown
>
Defined in
src/cache/src/index.ts:134
walkSync()
Synchronous form of Cache.walk()
Returns
Generator
<[string
, Buffer
], void
, unknown
>
Defined in
src/cache/src/index.ts:164
Type Aliases
BooleanOrVoid
Defined in
src/cache/src/index.ts:53
CacheFetchContext
Defined in
src/cache/src/index.ts:19
CacheOptions
Type declaration
fetchMethod?
fetchMethod may not be provided, because this cache forces its own read-from-disk as the fetchMethod
onDiskDelete()?
called whenever an item is deleted with cache.delete(key, true)
Deletes of the in-memory data do not trigger this method.
Parameters
• path: string
• key: string
• deleted: boolean
Returns
any
onDiskWrite()?
called whenever an item is written to disk.
Parameters
• path: string
• key: string
• data: Buffer
Returns
any
path
folder where items should be stored to disk
Defined in
src/cache/src/index.ts:25