/** * db4ai Query Cache * * Provides caching strategies for repeated queries with TTL, * LRU eviction, and cache invalidation support. * * @packageDocumentation */ /** * Cache configuration options. */ export interface CacheConfig { /** Maximum number of entries (default: 1000) */ maxEntries?: number; /** Maximum cache size in bytes (default: 50MB) */ maxSize?: number; /** Default TTL in milliseconds (default: 60000) */ defaultTtl?: number; /** Eviction policy (default: 'lru') */ evictionPolicy?: 'lru' | 'lfu' | 'fifo'; /** Enable cache statistics (default: true) */ enableStats?: boolean; /** Stale-while-revalidate window in ms (default: 0, disabled) */ staleWhileRevalidate?: number; } /** * Cache statistics. */ export interface CacheStats { /** Total number of hits */ hits: number; /** Total number of misses */ misses: number; /** Hit ratio (0-1) */ hitRatio: number; /** Current number of entries */ entries: number; /** Current size in bytes */ size: number; /** Number of evictions */ evictions: number; /** Number of expirations */ expirations: number; } /** * Cache get options. */ export interface CacheGetOptions { /** Allow returning stale data while revalidating */ allowStale?: boolean; } /** * Cache set options. */ export interface CacheSetOptions { /** Custom TTL for this entry */ ttl?: number; /** Tags for cache invalidation */ tags?: string[]; } /** * High-performance LRU cache with TTL support. * * Features: * - O(1) get/set operations using Map * - LRU/LFU/FIFO eviction policies * - Size-based eviction * - TTL with stale-while-revalidate support * - Tag-based cache invalidation * - Detailed statistics */ export declare class QueryCache { private readonly config; private readonly cache; private readonly tagIndex; private currentSize; private cleanupTimer; private hits; private misses; private evictions; private expirations; constructor(config?: CacheConfig); /** * Get a value from the cache. */ get(key: string, options?: CacheGetOptions): T | undefined; /** * Check if a key exists and is not expired. */ has(key: string): boolean; /** * Set a value in the cache. */ set(key: string, value: T, options?: CacheSetOptions): void; /** * Delete a specific entry. */ delete(key: string): boolean; /** * Invalidate all entries with a specific tag. */ invalidateByTag(tag: string): number; /** * Invalidate entries matching a pattern. */ invalidateByPattern(pattern: RegExp): number; /** * Clear all entries. */ clear(): void; /** * Get cache statistics. */ getStats(): CacheStats; /** * Reset statistics. */ resetStats(): void; /** * Get the current size in bytes. */ get size(): number; /** * Get the number of entries. */ get entries(): number; /** * Shutdown the cache. */ shutdown(): void; /** * Get or set a value (cache-aside pattern). */ getOrSet(key: string, factory: () => Promise, options?: CacheSetOptions): Promise; private estimateSize; private evictIfNeeded; private evictOne; private evictExpired; } /** * Generate a cache key from query parameters. */ export declare function generateCacheKey(collection: string, operation: string, params?: unknown): string; /** * Create a new query cache. */ export declare function createQueryCache(config?: CacheConfig): QueryCache; //# sourceMappingURL=cache.d.ts.map