/** * =============================================================================== * LRU CACHE WITH TTL SUPPORT * =============================================================================== * * LRU Cache with TTL support for multi-agent state management. * Prevents unbounded memory growth from stored intents, bindings, and missions. * * Features: * - Least Recently Used eviction when capacity is reached * - Time-To-Live (TTL) for automatic expiration * - Optional eviction callback for cleanup * - Efficient O(1) get/set operations using Map ordering * * =============================================================================== */ /** * Configuration for LRU Cache. */ export interface LRUCacheConfig { /** Maximum number of entries before eviction occurs */ maxSize: number; /** Time-to-live in milliseconds (optional, defaults to Infinity) */ ttlMs?: number; /** Callback invoked when an entry is evicted (optional) */ onEvict?: (key: string, value: unknown) => void; } /** * LRU Cache with TTL support. * * Uses Map's insertion order to track recency efficiently. * When an item is accessed, it's deleted and re-inserted to move it to the end. */ export declare class LRUCache { private cache; private config; constructor(config: LRUCacheConfig); /** * Set a value in the cache. * Evicts LRU entry if at capacity and key doesn't exist. */ set(key: string, value: T): void; /** * Get a value from the cache. * Returns undefined if not found or expired. * Updates access time and position for LRU tracking. */ get(key: string): T | undefined; /** * Check if a key exists and is not expired. */ has(key: string): boolean; /** * Delete an entry from the cache. * Invokes the onEvict callback if entry exists. */ delete(key: string): boolean; /** * Clear all entries from the cache. * Invokes onEvict callback for each entry. */ clear(): void; /** * Evict the least recently used entry. * Uses Map iteration order (oldest first). */ private evictLRU; /** * Clean up expired entries. * Returns the number of entries evicted. */ cleanup(): number; /** * Get all values in the cache (excluding expired). */ values(): T[]; /** * Get all keys in the cache (excluding expired). */ keys(): string[]; /** * Get all entries as [key, value] pairs (excluding expired). */ entries(): [string, T][]; /** * Get the current number of entries (may include expired entries). * Use cleanup() first for accurate count. */ size(): number; /** * Get cache statistics. */ stats(): { size: number; maxSize: number; ttlMs: number; }; /** * Iterate over cache entries with forEach. * Excludes expired entries. */ forEach(callback: (value: T, key: string) => void): void; /** * Filter entries matching a predicate. * Excludes expired entries. */ filter(predicate: (value: T, key: string) => boolean): T[]; /** * Find first entry matching a predicate. * Excludes expired entries. * Note: Uses Array.from for early exit support. */ find(predicate: (value: T, key: string) => boolean): T | undefined; /** * Update the TTL for a specific entry. * Useful for extending the life of active items. */ touch(key: string): boolean; /** * Get the remaining TTL for an entry in milliseconds. * Returns 0 if expired or not found. */ ttlRemaining(key: string): number; } /** * Create an LRU cache with common presets. */ export declare function createLRUCache(maxSize: number, options?: { ttlMs?: number; onEvict?: (key: string, value: unknown) => void; }): LRUCache; /** One hour in milliseconds */ export declare const ONE_HOUR_MS: number; /** 12 hours in milliseconds */ export declare const TWELVE_HOURS_MS: number; /** 24 hours in milliseconds */ export declare const TWENTY_FOUR_HOURS_MS: number; /** 7 days in milliseconds */ export declare const SEVEN_DAYS_MS: number; //# sourceMappingURL=lru-cache.d.ts.map