/** * Generic in-memory cache with TTL expiry, LRU eviction, and in-flight * request deduplication. * * Single source of truth for caching across the server — used by both the * API client (opt-in per-request caching) and the MCP resources layer. * * Design notes: * - Expiry is lazy: entries are pruned on access, not via a background timer. * - LRU order is tracked by `Map` insertion order; a "use" (get/set) moves the * key to the most-recently-used position by delete-then-reinsert. * - `getOrFetch` adds stampede prevention (concurrent misses share one fetch) * and a generation counter so a `clear()` mid-flight cannot repopulate the * cache with stale data. * - No tokens or auth data should ever be used as cache keys (caller's * responsibility — keys are endpoint + sorted params). */ /** Default time-to-live for entries when none is supplied — 5 minutes. */ export declare const DEFAULT_TTL_MS: number; /** Default maximum number of entries before LRU eviction kicks in. */ export declare const DEFAULT_MAX_ENTRIES = 100; /** Options for constructing a {@link MemoryCache}. */ export interface MemoryCacheOptions { /** Default TTL in milliseconds applied to `set`/`getOrFetch` calls without an explicit TTL. */ defaultTtlMs?: number; /** Maximum entries retained before the least-recently-used entry is evicted. */ maxEntries?: number; } /** * LRU + TTL in-memory cache. * * The instance type `T` describes the values stored via `get`/`set`. The * `getOrFetch` method is independently generic so a single shared cache can * hold heterogeneous values (instantiate as `MemoryCache`). */ export declare class MemoryCache { private readonly store; private readonly inflight; private readonly defaultTtlMs; private readonly maxEntries; private generation; constructor(options?: MemoryCacheOptions); /** Number of unexpired entries currently retained. */ get size(): number; /** * Return the cached value for `key`, or `undefined` if missing or expired. * A hit moves the key to the most-recently-used position. */ get(key: string): T | undefined; /** Return true only if `key` exists and is within its TTL. */ has(key: string): boolean; /** * Store `value` under `key` with an optional TTL override. * Evicts the least-recently-used entry if `maxEntries` would be exceeded. */ set(key: string, value: T, ttlMs?: number): void; /** Remove a single entry. Returns true if an entry was removed. */ delete(key: string): boolean; /** * Remove all entries and bump the generation counter so any in-flight * `getOrFetch` resolving after this call does not repopulate the cache. */ clear(): void; /** Alias for {@link clear}, kept for call sites that invalidate on token refresh. */ invalidateAll(): void; /** * Return the cached value for `key`, or run `fetcher` to populate it. * Concurrent misses for the same key share a single in-flight request. */ getOrFetch(key: string, ttlMs: number, fetcher: () => Promise): Promise; private evictIfNeeded; } //# sourceMappingURL=memory-cache.d.ts.map