UNPKG

codecrucible-synth

Version:

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

151 lines 4.45 kB
/** * Unified Cache System - Consolidates all cache implementations * * Architecture: * - Uses cache-manager.ts as the foundation (multi-layer: memory/redis/disk) * - Adds semantic search capabilities for AI responses * - Provides type-based routing for different data types * - Supports migration from legacy cache systems * * Based on audit findings: Consolidates 8 different cache systems into unified implementation */ import { EventEmitter } from 'events'; import { CacheConfig, CacheEntry } from './cache-manager.js'; export interface UnifiedCacheConfig extends CacheConfig { semantic: { enabled: boolean; similarityThreshold: number; embeddingDimension: number; maxVectorResults: number; }; routing: { strategies: CacheRoutingStrategy[]; }; } export interface CacheRoutingStrategy { name: string; pattern: RegExp; strategy: 'semantic' | 'standard' | 'security' | 'performance'; ttl?: number; layer?: 'memory' | 'redis' | 'disk'; } export interface SemanticCacheEntry<T = any> extends CacheEntry<T> { embedding?: number[]; similarity?: number; semanticKey?: string; } export interface CacheResult<T = any> { value: T; hit: boolean; source: 'exact' | 'semantic' | 'miss'; similarity?: number; metadata?: Record<string, any>; } /** * Unified Cache System - Single interface for all caching needs */ export declare class UnifiedCacheSystem extends EventEmitter { private cacheManager; private config; private vectorIndex; private embeddingCache; private legacyAdapters; constructor(config: UnifiedCacheConfig); /** * Main cache interface - routes to appropriate strategy based on key pattern */ get<T = any>(key: string, context?: Record<string, any>): Promise<CacheResult<T> | null>; /** * Main cache set interface - routes to appropriate strategy */ set<T = any>(key: string, value: T, options?: { ttl?: number; tags?: string[]; metadata?: Record<string, any>; embedding?: number[]; }): Promise<boolean>; /** * Semantic search implementation - extends standard caching with vector similarity */ private getWithSemanticSearch; /** * Semantic similarity search using vector embeddings */ private searchSemantically; /** * Set with semantic indexing for AI responses */ private setWithSemanticIndex; /** * Determine cache strategy based on key pattern */ private determineStrategy; /** * Standard cache operations (delegates to cache-manager) */ private getStandard; private setStandard; /** * Security-focused cache operations (encrypted, shorter TTL) */ private getSecure; private setSecure; /** * Performance-optimized cache operations (memory-only, longer TTL) */ private getPerformant; private setPerformant; /** * Generate embedding for semantic search (mock implementation) * TODO: Replace with actual embedding service (OpenAI, HuggingFace, etc.) */ private getEmbedding; /** * Calculate cosine similarity between two vectors */ private cosineSimilarity; /** * Legacy cache system migration support */ migrateLegacyCache(legacySystemName: string, adapter: LegacyCacheAdapter): Promise<void>; /** * Get comprehensive cache statistics */ getStats(): Promise<any>; /** * Delete a specific cache entry */ delete(key: string): Promise<boolean>; /** * Clear cache entries by tags */ clearByTags(tags: string[]): Promise<void>; /** * Clear all caches (unified operation) */ clear(): Promise<void>; /** * Cleanup and destroy */ destroy(): Promise<void>; } /** * Interface for migrating legacy cache systems */ export interface LegacyCacheAdapter { exportData(): Promise<Array<{ key: string; value: any; ttl?: number; tags?: string[]; metadata?: Record<string, any>; }>>; clear(): Promise<void>; } /** * Default configuration for unified cache system */ export declare const defaultUnifiedCacheConfig: UnifiedCacheConfig; export declare function getUnifiedCache(): UnifiedCacheSystem; export declare const unifiedCache: UnifiedCacheSystem; //# sourceMappingURL=unified-cache-system.d.ts.map