@croct/cache
Version:
An abstraction layer for caching.
21 lines (20 loc) • 690 B
TypeScript
import { CacheProvider } from './cacheProvider';
/**
* In-memory Least Recently Used (LRU) cache.
*/
export declare class LruCache<T = any> implements CacheProvider<string, T> {
private cache;
private readonly capacity;
private constructor();
/**
* Initializes a new instance with the given capacity.
*
* @param {number} capacity The maximum number of entries in the cache. Must be a
* positive safe integer.
*/
static ofCapacity(capacity: number): LruCache;
get(key: string, loader: (key: string) => Promise<T>): Promise<T>;
set(key: string, value: T): Promise<void>;
delete(key: string): Promise<void>;
private prune;
}