Skip to content

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.

K

readonly added: (key) => void

Defined in: packages/cache/src/cache.ts:278

A key the cache did not hold became resident, through set.

K

void


readonly used: (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.

K

void


readonly deleted: (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.

K

void


readonly chooseVictim: (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.

CacheVictimContext<K>

K


readonly optional clear?: () => 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.

void