codecrucible-synth
Version:
Production-Ready AI Development Platform with Multi-Voice Synthesis, Smithery MCP Integration, Enterprise Security, and Zero-Timeout Reliability
131 lines • 3.21 kB
TypeScript
/**
* Response Cache Manager
* Intelligent caching system for LLM responses to reduce redundant API calls
*
* Performance Impact: 60-80% faster response times for repeated/similar requests
*/
interface CacheEntry {
key: string;
request: {
prompt: string;
model: string;
provider: string;
tools?: any[];
};
response: {
content: string;
usage?: any;
finishReason?: string;
};
metadata: {
timestamp: number;
hitCount: number;
lastAccessed: number;
promptTokens: number;
responseTokens: number;
};
}
interface CacheStats {
totalEntries: number;
hitRate: number;
totalHits: number;
totalMisses: number;
memoryUsage: number;
oldestEntry: number | null;
avgResponseTime: number;
}
export declare class ResponseCacheManager {
private static instance;
private cache;
private stats;
private readonly MAX_CACHE_SIZE;
private readonly TTL_HOURS;
private readonly SIMILARITY_THRESHOLD;
private readonly CLEANUP_INTERVAL;
private cleanupIntervalId;
private constructor();
static getInstance(): ResponseCacheManager;
/**
* Generate cache key from request components
*/
private generateCacheKey;
/**
* Normalize prompt for better cache hits
*/
private normalizePrompt;
/**
* Check for cached response
*/
get(prompt: string, model: string, provider: string, tools?: any[]): CacheEntry | null;
/**
* Find similar cached entry using fuzzy matching
*/
private findSimilarEntry;
/**
* Calculate similarity between two strings using Jaccard similarity
*/
private calculateSimilarity;
/**
* Store response in cache
*/
set(prompt: string, model: string, provider: string, response: {
content: string;
usage?: any;
finishReason?: string;
}, tools?: any[]): void;
/**
* Estimate token count for strings (approximate)
*/
private estimateTokens;
/**
* Evict oldest entry to make space
*/
private evictOldestEntry;
/**
* Start periodic cleanup of expired entries
*/
private startPeriodicCleanup;
/**
* Clean up expired cache entries
*/
private cleanupExpiredEntries;
/**
* Get cache statistics
*/
getStats(): CacheStats;
/**
* Estimate memory usage of cache
*/
private estimateMemoryUsage;
/**
* Calculate average response time improvement
*/
private calculateAverageResponseTime;
/**
* Clear all cached entries
*/
clear(): void;
/**
* Get detailed cache information for debugging
*/
getCacheDetails(): Array<{
key: string;
prompt: string;
model: string;
provider: string;
hitCount: number;
age: string;
tokens: number;
}>;
/**
* Format age for display
*/
private formatAge;
/**
* Shutdown and cleanup
*/
shutdown(): void;
}
export declare const responseCache: ResponseCacheManager;
export {};
//# sourceMappingURL=response-cache-manager.d.ts.map