//#region src/index.d.ts /** * Interface for a cache. */ interface Cache { /** * Retrieve a value from the cache; * it will be returned with the remaining time-to-live (in seconds) if it exists. * * @param namespace * Isolated segment of the cache where keys are tracked. * @param key * Key. * @returns * Promise for a tuple with the value and TTL in seconds; * value will be `undefined` and TTL will be `0` if not found. */ get(namespace: string, key: string): Promise<[T | undefined, number]>; /** * Store a value in the cache. * * @param namespace * Isolated segment of the cache where keys are tracked. * @param key * Key. * @param value * Value. * @param ttl * Number of seconds the entry stays valid. * @returns * Nothing. */ set(namespace: string, key: string, value: T, ttl: number): void; } declare class Bucket { expires: Map; data: Map; constructor(); get(key: string): [T | undefined, number]; set(key: string, value: T, ttl: number): void; } /** * In-memory cache. */ declare class MemoryCache implements Cache { /** * Data. */ namespaces: Map>; /** * Create a new in-memory cache. */ constructor(); get(namespace: string, key: string): Promise<[T | undefined, number]>; set(namespace: string, key: string, value: T, ttl: number): void; } //#endregion export { Cache, MemoryCache };