/** * Speculative Cache - Speculative Execution v2.0 * * Stores pre-computed results from speculative execution with TTL-based expiration. * Provides instant (<10ms) cache lookups for predicted requests. * * Features: * - TTL-based expiration * - Confidence-based prioritization * - Memory-efficient storage * - Automatic cleanup */ import { EventEmitter } from 'events'; import { Prediction } from './PredictionEngine'; import { WorkerResult } from './WorkerPool'; export interface CacheEntry { id: string; prediction: Prediction; result: any; confidence: number; createdAt: number; expiresAt: number; hits: number; lastAccessedAt: number; } export interface SpeculativeCacheConfig { maxSize?: number; defaultTTL?: number; cleanupInterval?: number; maxMemoryMB?: number; } export interface SpeculativeCacheMetrics { size: number; hits: number; misses: number; hitRate: number; averageHitLatency: number; memoryUsageMB: number; evictions: number; } export declare class SpeculativeCache extends EventEmitter { private config; private cache; private cleanupTimer?; private metrics; private hitLatencies; constructor(config?: SpeculativeCacheConfig); /** * Start the cache */ start(): void; /** * Store a pre-computed result */ set(result: WorkerResult): void; /** * Get a cached result */ get(taskType: string, context: string): CacheEntry | null; /** * Find best matching entry using fuzzy matching */ private findBestMatch; /** * Calculate match score between request and cached prediction */ private calculateMatchScore; /** * Simple text similarity using word overlap */ private calculateTextSimilarity; /** * Generate cache key from prediction */ private generateKey; /** * Generate cache key from request */ private generateKeyFromRequest; /** * Simple string hash function */ private hashString; /** * Evict low priority entries */ private evictLowPriority; /** * Cleanup expired entries */ private cleanup; /** * Estimate memory usage in MB */ private getMemoryUsageMB; /** * Update metrics */ private updateMetrics; /** * Get current metrics */ getMetrics(): SpeculativeCacheMetrics; /** * Get all entries */ getEntries(): CacheEntry[]; /** * Clear all entries */ clear(): void; /** * Stop the cache */ stop(): void; } //# sourceMappingURL=SpeculativeCache.d.ts.map