/** * Distributed Cache System (Two-Tier: L1 Memory + L2 Redis) * * Provides distributed caching for multi-instance deployments using: * - L1: In-memory cache for fastest access (per-instance) * - L2: Redis (Upstash) for shared cache across instances * * Falls back gracefully when Redis is not configured. * * @example * ```typescript * // Basic usage * await cacheSet('user:123', userData, 300) * const user = await cacheGet('user:123') * * // With tags for invalidation * await cacheSet('user:123', userData, 300, ['users', 'user:123']) * await cacheInvalidateByTag('users') // Invalidates all user caches * ``` */ declare class L1MemoryCache { private cache; private tagIndex; private maxSize; private cleanupInterval; constructor(maxSize?: number); set(key: string, value: T, ttlMs: number, tags?: string[]): void; get(key: string): T | null; delete(key: string): boolean; invalidateByTag(tag: string): number; clear(): void; /** * Evicts the oldest entry (FIFO - First In, First Out). * JavaScript Maps maintain insertion order, so the first key is the oldest. */ private evictOldest; private cleanup; destroy(): void; getStats(): { size: number; maxSize: number; tagCount: number; }; } declare let l1Cache: L1MemoryCache; /** * Get a value from the distributed cache * * Checks L1 (memory) first, then L2 (Redis) if not found. * When found in L2, populates L1 for subsequent accesses. * * @param key - Cache key * @returns Cached value or null if not found/expired */ export declare function cacheGet(key: string): Promise; /** * Set a value in the distributed cache * * Stores in both L1 (memory) and L2 (Redis). * Uses tags for efficient bulk invalidation. * * @param key - Cache key * @param value - Value to cache * @param ttlSeconds - Time to live in seconds (default: 300 = 5 minutes) * @param tags - Optional tags for bulk invalidation */ export declare function cacheSet(key: string, value: T, ttlSeconds?: number, tags?: string[]): Promise; /** * Delete a specific key from the cache * * Removes from both L1 and L2. * * @param key - Cache key to delete */ export declare function cacheDelete(key: string): Promise; /** * Invalidate all cache entries with a specific tag * * Useful for invalidating related caches, e.g., all user-related caches * when user data changes. * * @param tag - Tag to invalidate * @returns Number of entries invalidated (from L1) */ export declare function cacheInvalidateByTag(tag: string): Promise; /** * Clear all cache entries * * Use with caution - clears entire cache. * Uses SCAN for Redis to avoid blocking (safe for production). */ export declare function cacheClear(): Promise; /** * Check if Redis is available for distributed caching */ export declare function isDistributedCacheAvailable(): Promise; /** * Get cache statistics */ export declare function getCacheStats(): Promise<{ l1: { size: number; maxSize: number; tagCount: number; }; l2Available: boolean; }>; /** * Helper to create cache keys with consistent naming */ export declare function createCacheKey(namespace: string, ...parts: string[]): string; export { l1Cache as _l1Cache }; /** * Reset function for testing (fix #7: properly destroy and recreate) */ export declare function _resetForTesting(): void; /** * Cleanup function for graceful shutdown (fix #1: lifecycle management) * Call this when your application is shutting down. */ export declare function destroyCache(): void; //# sourceMappingURL=distributed-cache.d.ts.map