API reference › @evolu/common › Cache › createLruCache
function createLruCache<K, V>(
capacity: number & Brand<"Int"> & Brand<"NonNegative"> & Brand<"Positive">,
): Cache<K, V>;
Defined in: packages/common/src/Cache.ts:53
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