/** * Generic LRU cache for `Collection`'s lazy hydration mode. * * Backed by a JavaScript `Map`, which preserves insertion order. Promotion * is implemented as `delete()` + `set()` — O(1) on `Map` since both * operations are constant-time. Eviction walks the iterator from the front * (least recently used) until both budgets are satisfied. * * ships in-memory only. The cache is never persisted; on collection * close every entry is dropped. Persisting cache state is a follow-up * once the access patterns from real consumers tell us whether it would * pay back the complexity. */ export interface LruEntry { /** The cached value. */ readonly value: V; /** * Approximate decrypted byte size of the entry. Used by the byte-budget * eviction path. Callers compute this once at insert time and pass it * in — recomputing on every access would dominate the per-record cost. */ readonly size: number; } export interface LruOptions { /** Maximum number of entries before eviction. Required if `maxBytes` is unset. */ maxRecords?: number; /** Maximum total bytes before eviction. Computed from per-entry `size`. */ maxBytes?: number; } export interface LruStats { /** Total cache hits since construction (or `resetStats()`). */ hits: number; /** Total cache misses since construction (or `resetStats()`). */ misses: number; /** Total entries evicted since construction (or `resetStats()`). */ evictions: number; /** Current number of cached entries. */ size: number; /** Current sum of cached entry sizes (in bytes, approximate). */ bytes: number; } /** * O(1) LRU cache. Both `get()` and `set()` promote the touched entry to * the most-recently-used end. Eviction happens after every insert and * walks the front of the Map iterator dropping entries until both * budgets are satisfied. */ export declare class Lru { private readonly entries; private readonly maxRecords; private readonly maxBytes; private currentBytes; private hits; private misses; private evictions; constructor(options: LruOptions); /** * Look up a key. Hits promote the entry to most-recently-used; misses * return undefined. Both update the running stats counters. */ get(key: K): V | undefined; /** * Insert or update a key. If the key already exists, its size is * accounted for and the entry is promoted to MRU. After insertion, * eviction runs to maintain both budgets. */ set(key: K, value: V, size: number): void; /** * Remove a key without affecting hit/miss stats. Used by `Collection.delete()`. * Returns true if the key was present. */ remove(key: K): boolean; /** True if the cache currently holds an entry for the given key. */ has(key: K): boolean; /** * Drop every entry. Stats counters survive — call `resetStats()` if you * want a clean slate. Used by `Collection.invalidate()` on key rotation. */ clear(): void; /** Reset hit/miss/eviction counters to zero. Does NOT touch entries. */ resetStats(): void; /** Snapshot of current cache statistics. Cheap — no copying. */ stats(): LruStats; /** * Iterate over all currently-cached values. Order is least-recently-used * first. Used by tests and devtools — production callers should use * `Collection.scan()` instead. */ values(): IterableIterator; /** * Walk the cache from the LRU end and drop entries until both budgets * are satisfied. Called after every `set()`. Single pass — entries are * never re-promoted during eviction. */ private evictUntilUnderBudget; private overBudget; }