Defined in: packages/cache/src/cache.ts:276
A caller-supplied eviction policy: the order in which a customCache
gives up its keys.
The cache owns every entry, weight, expiry, and validation; the policy sees
keys only and owns only the order it will evict them in. The cache tells it
when a key becomes resident, is used, or leaves, and asks it for a victim
when a set needs room. peek and has never report a use; like every
read, they report deleted when they drop an entry they find expired.
Every callback runs synchronously inside a cache member, and none may call
back into that cache: such a call throws CacheInvalidInputError with
code REENTRANT_POLICY. Reading size and totalWeight is allowed.
An error a callback throws propagates out of the cache member that called
it; customCache documents what each one leaves behind.
Type Parameters
Section titled “Type Parameters”K
Properties
Section titled “Properties”
readonlyadded: (key) =>void
Defined in: packages/cache/src/cache.ts:278
A key the cache did not hold became resident, through set.
Parameters
Section titled “Parameters”K
Returns
Section titled “Returns”void
readonlyused: (key) =>void
Defined in: packages/cache/src/cache.ts:280
A resident key was read with get, or replaced with set: a replacement counts as a use.
Parameters
Section titled “Parameters”K
Returns
Section titled “Returns”void
deleted
Section titled “deleted”
readonlydeleted: (key) =>void
Defined in: packages/cache/src/cache.ts:285
A resident key left the cache: deleted, dropped after it expired, or
evicted. Not called for clear.
Parameters
Section titled “Parameters”K
Returns
Section titled “Returns”void
chooseVictim
Section titled “chooseVictim”
readonlychooseVictim: (context) =>K
Defined in: packages/cache/src/cache.ts:293
Return the resident key to evict next. Called only while the cache holds
at least one key other than CacheVictimContext.protectedKey, and
before anything is removed for it. Returning a key the cache does not
hold, or the protected key, throws INVALID_VICTIM from set and leaves
that eviction undone. deleted follows for the returned key.
Parameters
Section titled “Parameters”context
Section titled “context”Returns
Section titled “Returns”K
clear?
Section titled “clear?”
readonlyoptionalclear?: () =>void
Defined in: packages/cache/src/cache.ts:298
Forget every key, because the cache was cleared. A policy that keeps any
per-key state must provide it: clear reports no deleted per key.
Returns
Section titled “Returns”void