@ende/cache
ende add jsr:@ende/cacheVersion 2026.10.15 on JSR.
In-memory cache utilities, such as memoization and caches with different expiration policies.
import { memoize, LruCache, type MemoizationCacheResult } from "@ende/cache";
import { assertEquals } from "@ende/assert";
const cache = new LruCache<string, MemoizationCacheResult<bigint>>(1000);
// fibonacci function, which is very slow for n > ~30 if not memoized
const fib = memoize((n: bigint): bigint => {
return n <= 2n ? 1n : fib(n - 1n) + fib(n - 2n);
}, { cache });
assertEquals(fib(100n), 354224848179261915075n);
Modules
Exports
LruCache— Least-recently-used cache.LruCacheEjectionReason— The reason an entry was removed from the cache.LruCacheOptions— Options for the LruCache constructor.MemoizationCache— A cache suitable for use with memoize.MemoizationCacheResult— The result of a memoized function, as stored in its cache.memoize— Cache the results of a function based on its arguments.MemoizeOptions— Options for memoize.TtlCache— Time-to-live cache.TtlCacheOptions— Options for the TtlCache constructor.TtlCacheSetOptions— Options for TtlCache.prototype.set.