/** * RESPONSE CACHING - Semantic & exact matching with Redis/Memcached * TTL management, cache invalidation, similarity-based retrieval */ export declare enum CacheStrategy { EXACT = "exact",// Exact prompt match SEMANTIC = "semantic",// Semantic similarity match PREFIX = "prefix",// Prefix-based match HYBRID = "hybrid" } export declare enum CacheBackend { MEMORY = "memory", REDIS = "redis", MEMCACHED = "memcached", CUSTOM = "custom" } export interface CacheConfig { enabled: boolean; backend: CacheBackend; strategy: CacheStrategy; ttl_seconds: number; max_size?: number; redis_url?: string; memcached_servers?: string[]; semantic_threshold?: number; embedding_model?: string; compression?: boolean; namespace?: string; } export interface CacheEntry { key: string; value: CachedResponse; created_at: Date; expires_at: Date; hits: number; last_accessed: Date; metadata?: Record; } export interface CachedResponse { prompt: string; response: string; model: string; provider: string; tokens_used?: number; cost?: number; latency_ms?: number; metadata?: Record; } export interface CacheHitResult { hit: boolean; entry?: CacheEntry; similarity_score?: number; cache_age_seconds?: number; } export interface CacheStats { total_requests: number; cache_hits: number; cache_misses: number; hit_rate: number; total_entries: number; memory_usage_bytes?: number; cost_saved?: number; tokens_saved?: number; } export declare class MemoryCacheBackend { private cache; private max_size; private eviction_policy; constructor(max_size?: number); get(key: string): Promise; set(key: string, entry: CacheEntry): Promise; delete(key: string): Promise; clear(): Promise; keys(pattern?: string): Promise; size(): Promise; private evict; } export declare class SemanticCache { private embeddings; private threshold; constructor(threshold?: number); /** * Find semantically similar cache entries */ findSimilar(_prompt: string, embedding: number[], limit?: number): Promise>; /** * Store embedding for a cache key */ storeEmbedding(key: string, embedding: number[]): Promise; /** * Delete embedding */ deleteEmbedding(key: string): Promise; /** * Clear all embeddings */ clear(): Promise; /** * Calculate cosine similarity between two vectors */ private cosineSimilarity; } export declare class CacheManager { private config; private backend; private semantic_cache?; private stats; constructor(config: CacheConfig); /** * Get cached response */ get(prompt: string, options?: { model?: string; provider?: string; embedding?: number[]; }): Promise; /** * Store response in cache */ set(prompt: string, response: CachedResponse, options?: { ttl_seconds?: number; embedding?: number[]; metadata?: Record; }): Promise; /** * Invalidate cache entries */ invalidate(pattern?: string): Promise; /** * Clear all cache */ clear(): Promise; /** * Get cache statistics */ getStats(): CacheStats; /** * Reset statistics */ resetStats(): void; /** * Get cache entries (for debugging/monitoring) */ getEntries(limit?: number): Promise; private generateKey; private hashString; private getCacheAge; private updateHitRate; private updateCostSavings; } export declare class CacheMiddleware { private cache_manager; constructor(config: CacheConfig); /** * Wrap a function with caching */ cached(key_fn: () => string, operation: () => Promise, options?: { ttl_seconds?: number; serializer?: (value: T) => string; deserializer?: (value: string) => T; }): Promise; /** * Get cache manager */ getCacheManager(): CacheManager; } //# sourceMappingURL=cache-manager.d.ts.map