export interface CacheEntryOptions { /** * Importance level. Higher value means less likely to be evicted by GC. * Default: 1 */ importance?: number; /** * Time to live in milliseconds. */ ttl?: number; /** * Absolute expiration date. */ expiresAt?: number; /** * Arbitrary metadata (optional). */ meta?: any; } export interface JkMemCacheOptions { /** * Name of the cache instance (used for logs). */ name: string; /** * Maximum number of items in cache. * Default: Infinity */ maxCount?: number; /** * Maximum size in bytes. * Default: 50MB (50 * 1024 * 1024) */ maxSize?: number; /** * Interval in milliseconds for the recurrent GC. * Default: 60000 (1 minute) */ cleanupInterval?: number; } export declare class JkMemCache { private _storage; private _currentSize; private _options; private _intervalId; private _name; constructor(options: JkMemCacheOptions); /** * Start the automatic cleanup interval. */ startAutoCleanup(): void; /** * Stop the automatic cleanup interval. */ stopAutoCleanup(): void; /** * Add or update an item in the cache. */ set(key: string, value: string | ArrayBuffer | Uint8Array | object, options?: CacheEntryOptions): void; /** * Retrieve an item from the cache. */ get(key: string, peek?: boolean): T | null; /** * Retrieve an item from the cache with its metadata. */ getWithMeta(key: string, peek?: boolean): { value: T; meta: any; size: number; } | null; /** * Check if an item exists in the cache and is not expired. * Does not increment accessCount. */ has(key: string): boolean; /** * Manually delete an item. */ delete(key: string): void; /** * Clear all items. */ clear(): void; /** * Get current cache stats. */ getStats(): { count: number; size: number; }; /** * Iterate over all valid keys. */ keys(): Generator; /** * Iterate over keys starting with a prefix. */ keysStartingWith(prefix: string): Generator; /** * Iterate over keys ending with a suffix. */ keysEndingWith(suffix: string): Generator; /** * Iterate over keys containing a specific text. */ keysContaining(text: string): Generator; /** * Check if we need to evict entries to fit a new one (or if limits are exceeded). */ private needsEviction; /** * Perform recurrent cleanup (expiration only). */ private performCleanup; /** * Evict items to make space/reduce count. * Strategy: Calculate a score. Lower score = evicted first. * Factors: * - expired (immediate kill) * - importance (higher = keep) * - accessCount (higher = keep) * * Score = (importance * 1000) + (accessCount) * (Simplified logic) */ private evictFor; }