UNPKG

codecrucible-synth

Version:

Production-Ready AI Development Platform with Multi-Voice Synthesis, Smithery MCP Integration, Enterprise Security, and Zero-Timeout Reliability

168 lines 3.83 kB
/** * Enterprise Caching System * Implements multi-layer caching with Redis, memory, and intelligent invalidation */ import { EventEmitter } from 'events'; export interface CacheEntry<T = any> { key: string; value: T; expiresAt: number; createdAt: number; lastAccessed: number; accessCount: number; tags: string[]; metadata?: Record<string, any>; } export interface CacheConfig { maxSize: number; defaultTTL: number; checkInterval: number; enableCompression: boolean; enableEncryption: boolean; encryptionKey?: string; layers: { memory: { enabled: boolean; maxSize: number; algorithm: 'lru' | 'lfu' | 'fifo'; }; redis: { enabled: boolean; host: string; port: number; password?: string; db: number; keyPrefix: string; }; disk: { enabled: boolean; path: string; maxSize: string; }; }; } export interface CacheStats { hits: number; misses: number; sets: number; deletes: number; evictions: number; hitRate: number; memoryUsage: number; keyCount: number; lastCleanup: Date; } export interface CacheOptions { ttl?: number; tags?: string[]; compress?: boolean; encrypt?: boolean; priority?: 'low' | 'normal' | 'high'; metadata?: Record<string, any>; } /** * Main Cache Manager */ export declare class CacheManager extends EventEmitter { private config; private memoryCache; private redisCache?; private stats; private cleanupInterval?; private encryptionKey?; constructor(config?: Partial<CacheConfig>); /** * Get value from cache */ get<T = any>(key: string): Promise<T | null>; /** * Set value in cache */ set<T = any>(key: string, value: T, options?: CacheOptions): Promise<void>; /** * Delete value from cache */ delete(key: string): Promise<boolean>; /** * Clear cache by tags */ deleteByTags(tags: string[]): Promise<number>; /** * Clear all cache */ clear(): Promise<void>; /** * Get cache statistics */ getStats(): CacheStats; /** * Get or set value with function */ getOrSet<T = any>(key: string, factory: () => Promise<T>, options?: CacheOptions): Promise<T>; /** * Warm up cache with data */ warmUp(data: Array<{ key: string; value: any; options?: CacheOptions; }>): Promise<void>; /** * Generate cache key with namespace */ private generateCacheKey; /** * Serialize value for storage */ private serializeValue; /** * Deserialize value from storage */ private deserializeValue; /** * Encrypt value */ private encrypt; /** * Decrypt value */ private decrypt; /** * Update cache statistics */ private updateStats; /** * Update hit rate */ private updateHitRate; /** * Estimate memory usage */ private estimateMemoryUsage; /** * Start cleanup timer */ private startCleanupTimer; /** * Clean up expired entries */ private cleanup; /** * Create Express caching middleware */ middleware(options?: { ttl?: number; keyGenerator?: (req: any) => string; skipIf?: (req: any) => boolean; tags?: string[]; }): (req: any, res: any, next: any) => Promise<any>; /** * Default key generator for middleware */ private defaultKeyGenerator; /** * Stop cache manager and cleanup */ stop(): Promise<void>; } //# sourceMappingURL=cache-manager.d.ts.map