/** * Options for `MJLruCache`. All fields are optional — defaults give a 1000-entry, * no-TTL cache. */ export interface MJLruCacheOptions { /** Maximum number of entries before LRU eviction kicks in. Default 1000. */ maxSize?: number; /** * Time-to-live in milliseconds. When set, entries older than this are treated * as missing on `Get()` and evicted lazily. Use 0 or undefined to disable TTL. */ ttlMs?: number; /** * Optional callback fired when an entry is evicted (LRU overflow, TTL expiry, * or explicit `Delete`/`Clear`). Useful for releasing handles owned by `V` * (e.g., calling `.destroy()` on an SDK client). */ onEvict?: (key: K, value: V, reason: 'lru' | 'ttl' | 'delete' | 'clear') => void; } /** * Bounded LRU cache with optional TTL — designed to replace the unbounded `Map` * fields that proliferate across MJ singletons (per-credential SDK client caches, * issuer caches, script caches, etc.). Built on `Map`'s preserved insertion order: * touching an entry deletes-and-reinserts to move it to the end, so eviction is * trivially the first key. * * - `Get` returns `undefined` for missing or expired entries and lazily evicts * expired ones (firing `onEvict` once). * - `Set` updates an existing entry in place (resetting recency + TTL) or evicts * the least-recently-used when `size === maxSize`. * - `onEvict` is called for **every** removal — overflow, expiry, explicit delete, * or `Clear()` — so callers can release SDK clients, sockets, etc. * * Thread-safety: same single-threaded JS guarantees as `Map`. Not safe across * worker threads — pin one cache per worker. * * NOTE: this is intentionally minimal. We don't expose `keys()`/`values()` * iterators because LRU semantics interact poorly with iteration order — callers * who need those should use `Map` directly. */ export declare class MJLruCache { private readonly _map; private readonly _maxSize; private readonly _ttlMs; private readonly _onEvict?; constructor(options?: MJLruCacheOptions); /** * Configured maximum entry count. Read-only after construction. */ get MaxSize(): number; /** * Current entry count (including any expired entries that haven't been * lazily evicted yet — call `Prune()` to force eviction first). */ get Size(): number; /** * Look up a value, refreshing its recency. Returns `undefined` if the key is * absent or the entry has expired. Expired entries are evicted lazily on the * miss (firing `onEvict` with reason `'ttl'`). */ Get(key: K): V | undefined; /** * Whether the key is present and unexpired. Does **not** refresh recency. */ Has(key: K): boolean; /** * Insert or replace an entry. If replacing, the old value is evicted with * reason `'delete'` so SDK-client style resources can be cleaned up. If * inserting and the cache is full, the LRU entry is evicted with reason * `'lru'`. */ Set(key: K, value: V): void; /** * Remove a key. Returns true if removed. Fires `onEvict` with reason * `'delete'`. */ Delete(key: K): boolean; /** * Remove every entry, firing `onEvict` for each with reason `'clear'`. */ Clear(): void; /** * Eagerly evict all expired entries. Useful from a periodic timer when * lazy eviction (only on `Get`/`Has`) isn't sufficient — for example, when * entries hold expensive resources you want released even if no one reads * them again. */ Prune(): number; } //# sourceMappingURL=MJLruCache.d.ts.map