import { Option, Writer } from 'adev-monads'; import { StorageAdapter } from './storage_adapter'; /** * @template T * @description Implements an LRU (Least Recently Used) Cache with TTL (Time-to-Live) support. * Allows for efficient storage and retrieval of key-value pairs. */ export declare class LRUCache { private static instance; private readonly capacity; private readonly hash; private head?; private tail?; private log; private hitCount; private missCount; private evictionCount; private readonly storageAdapter?; private constructor(); /** * Creates or retrieves the singleton instance of the LRU cache. * @template T * @param {number} [capacity=10] - Maximum capacity of the cache. * @returns {LRUCache} The singleton instance of the cache. */ static getInstance(capacity?: number, storageAdapter?: StorageAdapter): LRUCache; /** * Inserts or updates an item in the cache. * If the key already exists, it updates its value and moves it to the head. * If the cache exceeds capacity, the least recently used item is evicted. * @param {string} key - The key associated with the value. * @param {T} value - The value to store in the cache. * @param {number} [ttl=60000] - Time-to-Live in milliseconds for the item. * @returns {LRUCache} The current cache instance for chaining. */ put(key: string, value: T, ttl?: number): LRUCache; /** * Retrieves an item from the cache by key. * If the item has expired, it returns undefined and counts as a miss. * @param {string} key - The key to search for. * @returns {T | undefined} The value associated with the key, or undefined if not found or expired. */ get(key: string): T | undefined; /** * Retrieves an item from the cache by key, wrapped in an Option monad. * If the item has expired, it returns an Option.None and counts as a miss. * * This method provides a functional approach to handle the absence of values, * allowing the caller to use methods like `map`, `filter`, and `getOrElse` * to safely work with the result. * * @param {string} key - The key to search for. * @returns {Option} An Option.Some containing the value if found and valid, * or Option.None if not found or expired. */ getOption(key: string): Option; /** * Clears all items from the cache. */ clear(): void; private prepend; private pop; private removeFromPosition; private getHitRate; private getMissRate; private getEvictionRate; /** * Resets cache performance metrics. */ clearMetrics(): void; /** * Logs cache performance metrics to the console. * Includes hit rate, miss rate, and eviction rate. */ logMetrics(): Writer; /** * Logs debugging information about the cache to the console. * Includes the current state of the linked list and the hash map. */ debugLRU(): void; }