UNPKG

flight-planner

Version:
78 lines (77 loc) 2.29 kB
/** * A generic LRU cache service with TTL support. */ export declare class CacheService<K, V> { private cache; private accessOrder; private maxCacheSize; private defaultTTL; /** * Creates a new instance of the CacheService class. * * @param maxCacheSize - Maximum number of items to keep in the cache (default: 1000). * @param defaultTTL - Default time-to-live in milliseconds, or null for no expiry (default: null). */ constructor(maxCacheSize?: number, defaultTTL?: number | null); /** * Retrieves an item from the cache. * * @param key - The key of the item to retrieve. * @returns The cached item, or undefined if not found or expired. */ get(key: K): V | undefined; /** * Adds or updates an item in the cache. * * @param key - The key of the item to add or update. * @param value - The item to cache. * @param ttl - Time-to-live in milliseconds, or null for no expiry. Uses defaultTTL if not specified. */ set(key: K, value: V, ttl?: number | null): void; /** * Checks if an item exists in the cache and is not expired. * * @param key - The key of the item to check. * @returns True if the item exists and is not expired, false otherwise. */ has(key: K): boolean; /** * Deletes an item from the cache. * * @param key - The key of the item to delete. */ delete(key: K): void; /** * Returns an array of keys in the cache. * This does not check for expired items. * * @returns An array of keys. */ keys(): K[]; /** * Returns an array of values in the cache. * This does not check for expired items. * * @returns An array of values. */ values(): V[]; /** * Clears all items from the cache. */ clear(): void; /** * Removes all expired items from the cache. * * @returns The number of items removed. */ cleanExpired(): number; /** * Updates the access order for the LRU cache. * @param key - The key that was accessed. */ private updateAccessOrder; /** * Enforces the cache size limit by removing least recently used items. */ private enforceCacheLimit; }