/** * A cached version of a function with management methods attached. * * @group Cache */ export type Cached any> = F & { /** * Drops every memoized result. */ clear(): void; /** * Drops the memoized result for a specific argument set. */ delete(...args: Parameters): void; }; /** * Caches the result of a function call by its arguments. * * Returned function exposes `.clear()` and `.delete(...args)` for manual invalidation. * Optional `maxSize` enables LRU eviction; optional `ttl` (ms) makes entries expire. * Promises are unwrapped — only the resolved value is stored, so concurrent calls share one inflight Promise. * * @example * ``` * const fetchUser = cache( * (id: string) => fetch(`/users/${id}`).then(r => r.json()), * { maxSize: 100, ttl: 60_000 }, * ) * fetchUser('1') // network call * fetchUser('1') // cached * fetchUser.delete('1') // drop one entry * fetchUser.clear() // drop all * ``` * @group Cache */ export declare function cache any>(func: F, options?: { /** * When set, evicts the least-recently-used entry once the cache exceeds this size. */ maxSize?: number; /** * Time-to-live in milliseconds. Entries older than this are recomputed on read. */ ttl?: number; }): Cached;