/** * Prompt Cache Module * * Simple LRU cache for frequently accessed prompts. * Reduces database queries for repeated prompt lookups. */ import type { PromptRecord } from '../llm_api/types.js'; /** * Cache configuration options */ export interface PromptCacheConfig { /** Time-to-live in milliseconds (default: 5 minutes) */ ttl_ms?: number; /** Maximum number of entries (default: 100) */ max_size?: number; /** Whether caching is enabled (default: true) */ enabled?: boolean; } /** * Cache statistics */ export interface CacheStats { hits: number; misses: number; size: number; max_size: number; hit_rate: number; } /** * Simple LRU cache for prompts * * @example * ```typescript * const cache = new PromptCache({ ttl_ms: 60000, max_size: 50 }); * * // Check cache first * const cached = cache.get('marketing', 'greeting'); * if (cached) { * return cached; * } * * // Fetch from database and cache * const prompt = get_prompt_by_area_and_key(db, 'marketing', 'greeting', logger); * if (prompt) { * cache.set(prompt); * } * ``` */ export declare class PromptCache { private cache; private ttl_ms; private max_size; private enabled; private hits; private misses; constructor(config?: PromptCacheConfig); /** * Generate cache key from area and key */ private make_key; /** * Check if an entry is expired */ private is_expired; /** * Evict least recently used entries if cache is full */ private evict_if_needed; /** * Get a prompt from the cache * * @param area - Prompt area * @param key - Prompt key * @returns Cached prompt or null if not found/expired */ get(area: string, key: string): PromptRecord | null; /** * Get a prompt by ID from the cache * * @param id - Prompt ID (UUID) * @returns Cached prompt or null if not found/expired */ get_by_id(id: string): PromptRecord | null; /** * Add a prompt to the cache * * @param prompt - Prompt record to cache */ set(prompt: PromptRecord): void; /** * Remove a prompt from the cache * * @param area - Prompt area * @param key - Prompt key */ invalidate(area: string, key: string): void; /** * Remove a prompt by ID from the cache * * @param id - Prompt ID (UUID) */ invalidate_by_id(id: string): void; /** * Invalidate all prompts in an area * * @param area - Prompt area to invalidate */ invalidate_area(area: string): void; /** * Clear all cached entries */ clear(): void; /** * Remove all expired entries * * @returns Number of entries removed */ cleanup(): number; /** * Get cache statistics */ get_stats(): CacheStats; /** * Enable or disable the cache * * @param enabled - Whether to enable caching */ set_enabled(enabled: boolean): void; /** * Check if caching is enabled */ is_enabled(): boolean; } /** * Get the global prompt cache instance * Creates one with default settings if not configured * * @returns Global prompt cache */ export declare function get_prompt_cache(): PromptCache; /** * Configure the global prompt cache * * @param config - Cache configuration options */ export declare function configure_prompt_cache(config: PromptCacheConfig): void; /** * Clear the global prompt cache */ export declare function clear_prompt_cache(): void; /** * Invalidate a specific prompt in the global cache by area and key * * @param area - Prompt area * @param key - Prompt key */ export declare function invalidate_prompt_cache(area: string, key: string): void; /** * Invalidate a specific prompt in the global cache by ID * * @param id - Prompt ID (UUID) */ export declare function invalidate_prompt_cache_by_id(id: string): void; //# sourceMappingURL=prompt_cache.d.ts.map