/** * LRU Cache with TTL (Time To Live) * * Provides a cache implementation with: * - TTL (Time To Live) expiration * - Size limits with LRU eviction * - Type-safe generic interface * * @example * ```typescript * const cache = new LRUCache({ maxSize: 100, ttlMs: 5 * 60 * 1000 }) * const user = await cache.fetch('user:123', () => fetchUserFromDB('123')) * ``` */ export interface LRUCacheOptions { /** * Maximum number of entries in the cache * @default 100 */ maxSize?: number; /** * Time to live in milliseconds * @default 5 minutes (300000) */ ttlMs?: number; } /** * LRU Cache with TTL for storing key-value pairs * * Features: * - Automatic expiration based on TTL * - Size limits with LRU (Least Recently Used) eviction * - Type-safe generic interface */ export declare class LRUCache { private cache; private readonly maxSize; private readonly ttlMs; constructor(options?: LRUCacheOptions); /** * Fetch a value from cache or compute it using the fetcher function * * @param key - Cache key * @param fetcher - Function to fetch the value if not in cache * @returns The cached or newly fetched value */ fetch(key: K, fetcher: () => Promise | V): Promise; /** * Get a value from cache without fetching (returns undefined if not found or expired) * * @param key - Cache key * @returns The cached value or undefined */ get(key: K): V | undefined; /** * Set a value in the cache * * @param key - Cache key * @param value - Value to cache */ set(key: K, value: V): void; /** * Delete a value from the cache * * @param key - Cache key * @returns true if the entry was deleted, false if it didn't exist */ delete(key: K): boolean; /** * Clear all entries from the cache */ clear(): void; /** * Get the current size of the cache */ get size(): number; /** * Evict expired entries and LRU entries if at capacity */ private evictIfNeeded; /** * Clean up expired entries (can be called periodically) */ cleanup(): void; } //# sourceMappingURL=cache.d.ts.map