In-memory cache utilities, such as memoization and caches with different expiration policies.
import { memoize, LruCache, type MemoizationCacheResult } from "@std/cache";import { assertEquals } from "@std/assert";const cache = new LruCache<string, MemoizationCacheResult<bigint>>(1000);// fibonacci function, which is very slow for n > ~30 if not memoizedconst fib = memoize((n: bigint): bigint => { return n <= 2n ? 1n : fib(n - 1n) + fib(n - 2n);}, { cache });assertEquals(fib(100n), 354224848179261915075n); Copy
import { memoize, LruCache, type MemoizationCacheResult } from "@std/cache";import { assertEquals } from "@std/assert";const cache = new LruCache<string, MemoizationCacheResult<bigint>>(1000);// fibonacci function, which is very slow for n > ~30 if not memoizedconst fib = memoize((n: bigint): bigint => { return n <= 2n ? 1n : fib(n - 1n) + fib(n - 2n);}, { cache });assertEquals(fib(100n), 354224848179261915075n);
In-memory cache utilities, such as memoization and caches with different expiration policies.