/** All options are optional. */ type LRUMapOptions = { /** * Maximum number of entries. Oldest entry is evicted when exceeded. * Defaults to no limit. 0 means "no max", not "no entries allowed". */ maxSize?: number; /** * Time-to-live in milliseconds. Entries expire after this duration. * Defaults to no expiration. 0 means "no expiration", not * "expires immediately". */ ttlMs?: number; }; /** * Strongly-typed LRU cache that implements the Map interface. You can also use * this as a size-limited map by setting maxSize. * * Values can be null, but cannot be undefined. */ declare class LRUMap implements Map { private readonly options; private readonly map; private readonly head; private readonly tail; constructor(options?: LRUMapOptions); /** * Store a value. Overwrites any existing entry for the key. * Note: Disallow setting a custom TTL because that will require us to do a * sorted insertion instead of an insert-at-front. */ set(key: K, value: V): this; /** * Retrieve a value and mark it as recently used. * Returns `undefined` on miss or if the entry has expired. */ get(key: K): V | undefined; /** * Read a value WITHOUT updating recency or hit/miss stats. * Useful for inspection or monitoring without polluting cache order. */ peek(key: K): V | undefined; /** * Get the existing value, or return a default value. Will not set the value * in the map. */ getOrDefault(key: K, defaultValue: V): V; /** Required by Map interface. */ getOrInsert(key: K, value: V): V; /** Required by Map interface. */ getOrInsertComputed(key: K, callback: (key: K) => V): V; /** Same as getOrInsertComputed, but async. */ getOrInsertLoaded(key: K, loader: (key: K) => Promise): Promise; /** Returns true if the key exists and has not expired. */ has(key: K): boolean; /** Remove a single entry. Returns true if the key existed. */ delete(key: K): boolean; /** Remove all entries. */ clear(): void; /** Number of entries currently in the cache (including expired ones). */ get size(): number; get [Symbol.toStringTag](): string; /** Filter out expired entries. */ keys(): MapIterator; /** Filter out expired entries. */ values(): MapIterator; /** * Iterate over [key, value] pairs (in insertion order), skipping expired * entries. * NOTE: Do not delete any entries, otherwise it will break the LRU data. */ entries(): MapIterator<[K, V]>; /** NOTE: Do not delete any entries, otherwise it will break the LRU data. */ [Symbol.iterator](): MapIterator<[K, V]>; /** * NOTE: Do not use the `map` argument as it will always be an empty Map. * The actual underlying map has a different value type. */ forEach(callbackFn: (value: V, key: K, map: Map) => void, thisArg?: unknown): void; private calcExpiry; private isExpired; private peekEntry; private unrefTimer; private setupExpiryTimeout; private insertAtFront; private removeFromList; private moveToFront; private evictOldestEntry; private deleteEntry; } export { LRUMap, type LRUMapOptions };