Built and signed on GitHub ActionsBuilt and signed on GitHub Actions
UNSTABLE: Cache utilities
Classes
Least-recently-used cache.
- clear(): void
Clears the cache.
- delete(key: K): boolean
Deletes the value associated with the given key.
- get(key: K): V | undefined
Gets the element with the specified key.
- has(key: K): boolean
Checks whether an element with the specified key exists or not. Does not update the entry's position in the eviction order.
- maxSize(): number
The maximum number of entries to store in the cache.
- peek(key: K): V | undefined
Returns the value associated with the given key, or
undefinedif the key is not present, without updating its position in the eviction order. - set(): thiskey: K,value: V
Sets the specified key to the specified value.
Time-to-live cache.
- clear(): void
Clears the cache.
- delete(key: K): boolean
Deletes the value associated with the given key.
- get(key: K): V | undefined
Gets the value associated with the specified key.
- peek(key: K): V | undefined
Returns the value associated with the given key, or
undefinedif the key is not present, without resetting its TTL. - set(): thiskey: K,value: V,options?: TtlCacheSetOptions
Set a value in the cache.
Functions
Cache the results of a function based on its arguments.
Interfaces
Options for the LruCache constructor.
- onEject: () => voidejectedKey: K,ejectedValue: V,reason: LruCacheEjectionReason
Callback invoked when an entry is removed, whether by eviction, manual deletion, or clearing the cache. The entry is already removed from the cache when this callback fires. Overwriting an existing key via
set()does not trigger this callback. The cache is not re-entrant during this callback: callingset,delete, orclearwill throw.
A cache suitable for use with memoize.
- delete(key: K): unknown
Removes the value associated with the given key from the cache.
- get(key: K): V | undefined
Returns the cached value associated with the given key, if present.
- has(key: K): boolean
Checks whether a value for the given key exists in the cache.
- set(): unknownkey: K,val: V
Stores a value in the cache under the given key.
Options for the TtlCache constructor.
- onEject: () => voidejectedKey: K,ejectedValue: V
Callback invoked when an entry is removed, whether by TTL expiry, manual deletion, or clearing the cache.
- slidingExpiration: boolean
When
true, eachget()call resets the entry's TTL.
Options for TtlCache.prototype.set.
- absoluteExpiration: number
A maximum lifetime in milliseconds for this entry, measured from the time it is set. When
slidingExpirationis enabled, the sliding window cannot extend past this duration. Throws ifslidingExpirationis not enabled. - ttl: number
A custom time-to-live in milliseconds for this entry. If supplied, overrides the cache's default TTL. Must be a finite, non-negative number.
Type Aliases
The reason an entry was removed from the cache.
| { kind: "error"; error: unknown; }
| (T extends Promise<unknown> ? { kind: "promise"; value: T; } : never)
The result of a memoized function, as stored in its cache.
Options for memoize.
- cache: Cache
Provide a custom cache for getting previous results. By default, a new
Mapobject is instantiated upon memoization and used as a cache, with no limit on the number of results to be cached. - errorIsCacheable: (err: unknown) => boolean
Callback to determine if an error or other thrown value is cacheable.
- getKey: () => Keythis: ThisParameterType<Fn>,...args: Parameters<Fn>
Function to get a unique cache key from the function's arguments. By default, a composite key is created from all the arguments plus the
thisvalue, using reference equality to check for equivalence.