confinode
Version:
Node application configuration reader
51 lines (50 loc) • 1.24 kB
TypeScript
/**
* A LRU cache with a timeout.
*/
export default class Cache<T> {
private readonly maxAge;
/**
* The LRU used for the cache.
*/
private readonly lru;
/**
* The idle timer, used to clear cache if not used during a long time.
*/
private timer;
/**
* The cache constructor.
*
* @param maxAge - The maximum amount of time in milliseconds the cache is kept alive while unused.
* @param capacity - The maximum amount of objects kept in cache.
*/
constructor(maxAge: number, capacity: number);
/**
* Set the item.
*
* @param key - The key of the item.
* @param value - The item to cache.
*/
set(key: string, value: T): void;
/**
* Test if the key is in the cache.
*
* @param key - The key to test.
* @returns True if the key is in the cache.
*/
has(key: string): boolean;
/**
* Retrieve the cached item.
*
* @param key - The key of the item to retrieve.
* @returns The cached item.
*/
get(key: string): T | undefined;
/**
* Clear the content of the cache.
*/
clear(): void;
/**
* Clean the stale objects.
*/
private resetTimer;
}