/** * API Response Cache * @module api/cache * * SMI-1245: Caching layer for API responses * * Provides in-memory caching with TTL for offline support. * Uses a simple LRU-like eviction strategy. */ /** * Cache configuration */ export interface CacheConfig { /** Default TTL in milliseconds (default: 1 hour) */ defaultTtl?: number; /** Max entries in cache (default: 1000) */ maxEntries?: number; /** Enable cache statistics (default: false) */ enableStats?: boolean; } /** * Cache statistics */ export interface CacheStats { hits: number; misses: number; entries: number; evictions: number; hitRate: number; } /** * TTL configuration for different endpoints */ export declare const DEFAULT_TTL: Record; /** * API Response Cache * * @example * ```typescript * const cache = new ApiCache({ defaultTtl: 3600000 }); * * // Cache a search result * cache.set('search:testing', results, 'search'); * * // Get from cache * const cached = cache.get('search:testing'); * ``` */ export declare class ApiCache { private cache; private defaultTtl; private maxEntries; private enableStats; private hits; private misses; private evictions; private operationCount; private readonly PRUNE_INTERVAL; constructor(config?: CacheConfig); /** * Generate cache key from endpoint and parameters */ static createKey(endpoint: string, params?: Record): string; /** * Get item from cache */ get(key: string): T | undefined; /** * Set item in cache */ set(key: string, data: T, endpointType?: keyof typeof DEFAULT_TTL): void; /** * Check if key exists and is not expired */ has(key: string): boolean; /** * Delete item from cache */ delete(key: string): boolean; /** * Clear all cache entries */ clear(): void; /** * Clear expired entries */ prune(): number; /** * Invalidate entries matching a pattern. * * When a string is provided, it is treated as a literal string and * special RegExp characters are escaped to prevent RegExp injection. * To use regex patterns, pass a RegExp object directly. * * @param pattern - Literal string to match or RegExp for pattern matching * @returns Number of entries invalidated * * @example * ```typescript * // Literal string matching (special chars are escaped) * cache.invalidatePattern('search:user.name') // Matches exactly 'search:user.name' * * // RegExp for pattern matching * cache.invalidatePattern(/^search:/) // Matches all keys starting with 'search:' * ``` */ invalidatePattern(pattern: string | RegExp): number; /** * Get cache statistics */ getStats(): CacheStats; /** * Automatically prune expired entries every PRUNE_INTERVAL operations. * SMI-1262: Prevents expired entries from accumulating until maxEntries is reached. */ private maybeAutoPrune; /** * Evict least recently used entries */ private evictLeastUsed; } /** * Create a cache instance with default configuration */ export declare function createCache(config?: CacheConfig): ApiCache; /** * Get or create the global cache instance */ export declare function getGlobalCache(): ApiCache; export default ApiCache; //# sourceMappingURL=cache.d.ts.map