/** * SMI-644: Cache Entry Data Structure * Enhanced cache entry with TTL tracking and hit count for popularity detection */ import type { SearchResult } from './lru.js'; /** * TTL tiers based on query popularity */ export declare enum TTLTier { /** Popular queries (>10 hits/hour): 4 hours */ POPULAR = 14400000, /** Standard queries: 1 hour */ STANDARD = 3600000, /** Rare queries (<1 hit/day): 15 minutes */ RARE = 900000 } /** * Popularity thresholds for TTL determination */ export declare const POPULARITY_THRESHOLDS: { /** Hits per hour to be considered "popular" */ readonly POPULAR_HITS_PER_HOUR: 10; /** Minimum age (ms) before evaluating popularity */ readonly MIN_AGE_FOR_EVALUATION: number; }; /** * Enhanced cache entry with TTL and popularity tracking */ export interface CacheEntry { /** Unique cache key */ key: string; /** Cached data */ data: T; /** Total count for search results */ totalCount: number; /** Creation timestamp (ms) */ createdAt: number; /** Expiration timestamp (ms) */ expiresAt: number; /** Number of cache hits */ hitCount: number; /** Last access timestamp (ms) */ lastAccessedAt: number; /** Current TTL tier */ ttlTier: TTLTier; } /** * Serialized format for persistent storage */ export interface SerializedCacheEntry { key: string; data_json: string; total_count: number; created_at: number; expires_at: number; hit_count: number; last_accessed_at: number; ttl_tier: number; } /** * Create a new cache entry with default TTL */ export declare function createCacheEntry(key: string, data: T, totalCount: number, ttlTier?: TTLTier): CacheEntry; /** * Record a hit on a cache entry * Returns updated entry (immutable pattern) */ export declare function recordHit(entry: CacheEntry): CacheEntry; /** * Calculate TTL tier based on hit rate */ export declare function calculateTTLTier(createdAt: number, hitCount: number, now?: number): TTLTier; /** * Check if cache entry is expired */ export declare function isExpired(entry: CacheEntry, now?: number): boolean; /** * Check if entry should be refreshed (approaching expiration) * Returns true if within 10% of TTL remaining */ export declare function shouldRefresh(entry: CacheEntry, now?: number): boolean; /** * Validate cache key for security (standards.md §4) * Prevents injection attacks through cache keys */ export declare function isValidCacheKey(key: string): boolean; /** * Serialize cache entry for persistence * Uses safe JSON serialization to prevent prototype pollution */ export declare function serializeCacheEntry(entry: CacheEntry): SerializedCacheEntry; /** * Deserialize cache entry from persistence * Validates data to prevent prototype pollution (security: standards.md §4) */ export declare function deserializeCacheEntry(serialized: SerializedCacheEntry): CacheEntry; /** * Get human-readable TTL tier name */ export declare function getTTLTierName(tier: TTLTier): string; //# sourceMappingURL=CacheEntry.d.ts.map