interface CacheOptions { ttl?: number; /** * Maximum number of entries. Exceeding it drops the least recently used ones. */ capacity?: number; /** * Byte budget across all entries. Only has an effect together with `sizeOf`. */ maxBytes?: number; /** * Byte cost of a value, used for the `maxBytes` budget. */ sizeOf?: (value: V) => number; /** * Called whenever an entry leaves the cache. `replacedValue` is the value that * left, `value` the new one for that key, set only on replacement. */ onEvict?: (event: { key: K; replacedValue: V; value?: V; }) => void; } export default class Cache { private map; private totalBytes; private readonly ttl; private readonly capacity; private readonly maxBytes; private readonly sizeOf?; private readonly onEvict?; constructor(options: CacheOptions); /** * Byte cost of all entries, as reported by `sizeOf`. */ get bytes(): number; set(key: K, value: V, ttl?: number): V; get(key: K): V; delete(key: K): boolean; clear(): void; entries(): [K, V][]; keys(): K[]; has(key: K): boolean; values(): V[]; /** * Drops all expired entries. This is only needed before handing out the whole * content of the cache. */ evict(): void; private drop; /** * Moves an entry to the end of the map, where the most recently used ones live. */ private touch; /** * Evicts least recently used entries until capacity and byte budget are met. */ private trim; } export {};