import { ICacheMetricsRecorder } from '../ICacheMetricsRecorder'; import { ICacheStats } from '../ICacheStats'; import { ILayeredCache } from '../interfaces/ILayeredCache'; /** * Configuration options for {@link MemoryLayeredCache}. * * @public */ export interface ILayeredCacheOptions { /** * Time to live in milliseconds. Entries older than this are considered expired. * Defaults to infinite (no expiration). * * @public */ ttlMs?: number; /** * When `true`, expired entries are served immediately while a background * refresh is triggered. Defaults to `false`. * * @public */ staleWhileRevalidate?: boolean; /** * Maximum number of entries retained in the cache. Oldest entries are * evicted first (LRU). Defaults to infinite. * * @public */ maxEntries?: number; /** * Optional metrics recorder forwarded cache operation statistics. * Falls back to {@link NoopCacheMetricsRecorder} when omitted. * * @public */ metricsRecorder?: ICacheMetricsRecorder; /** * An optional name / label for the cache instance, used in metrics. * Defaults to `'memory'`. * * @public */ cacheName?: string; } /** * In-memory layered cache with LRU eviction, TTL expiration and * optional stale-while-revalidate support. Falls back to an * asynchronous loader function on cache misses. * * @public * @template TKey The type of the cache keys. * @template TValue The type of the cache values. */ export declare class MemoryLayeredCache implements ILayeredCache { private readonly _store; private readonly _logger; private readonly _loadFn; private readonly _options; private readonly _metrics; private readonly _cacheName; private _hits; private _misses; private _loads; private _loadErrors; private _evictions; /** * Initializes a new instance of the {@link MemoryLayeredCache} class. * * @param loadFn - Async loader invoked on cache misses. * @param options - Optional configuration for TTL, LRU and metrics. */ constructor(loadFn: (key: TKey) => Promise, options?: ILayeredCacheOptions); /** @inheritdoc */ get(key: TKey): TValue | undefined; /** @inheritdoc */ getAsync(key: TKey): Promise; /** @inheritdoc */ set(key: TKey, value: TValue): void; /** @inheritdoc */ setAsync(key: TKey, value: TValue): Promise; /** @inheritdoc */ warm(key: TKey): Promise; /** @inheritdoc */ invalidate(key: TKey): void; /** @inheritdoc */ invalidateAsync(key: TKey): Promise; /** @inheritdoc */ stats(): ICacheStats; private _isExpired; private _loadFresh; private _refresh; private _touch; private _insert; private _enforceMax; }