API reference / @evolu/common / Cache / createLruCache

Function: createLruCache()

function createLruCache<K, V>(capacity): Cache<K, V>;

Defined in: packages/common/src/Cache.ts:44

Creates an LRU (least recently used) cache with a maximum capacity.

When the cache reaches capacity, the least recently used entry is evicted. Both get and set operations update the access order.

Example

const cache = createLruCache<string, number>(2);
cache.set("a", 1);
cache.set("b", 2);
cache.set("c", 3); // Evicts "a"
cache.has("a"); // false

Type Parameters

Type Parameter
K
V

Parameters

ParameterType
capacitynumber & Brand<"Int"> & Brand<"NonNegative"> & Brand<"Positive">

Returns

Cache<K, V>

Was this page helpful?