UNPKG

@newdash/newdash

Version:

javascript/typescript utility library

64 lines (63 loc) 1.82 kB
/** * TTL (Time to Life) Map * * it will lazy remove values when perform operations * * @category Functional * @since 5.18.0 */ export declare class TTLMap<K = any, V = any> extends Map<K, V> { /** * TTLMap (Time to Life) Map * * it will lazy remove values when perform operations * * @param defaultTTL time to live, in milliseconds, default value is 60 seconds * @param cleanAfterOperation execute full clean after operations. default value is 100, it means, at least 100 operations performed, the TTL evict logic will be executed */ constructor(defaultTTL?: number, cleanAfterOperation?: number); /** * default TTL value in milliseconds */ private defaultTTL; private cleanAfterOperation; private operationCount; private timeoutStorage; private timestamp; /** * _checkAndClean * * for the simple operations (set/get/delete/has), the clean operation will not execute every time */ private _checkAndClean; /** * set value * * @param k key * @param v value * @param ttl time to live, in milliseconds, if undefined, will use instance level defaultTTL * @returns */ set(k: K, v: V, ttl?: number): this; has(k: K): boolean; get(k: K): V | undefined; delete(k: K): boolean; clear(): void; /** * return true if timeout * * @param k */ private checkTimeout; private getTimeout; /** * manually directly clean all timeout items */ cleanTimeoutItems(): void; entries(): IterableIterator<[K, V]>; keys(): IterableIterator<K>; values(): IterableIterator<V>; forEach(callbackfn: (value: V, key: K, map: Map<K, V>) => void, thisArg?: any): void; get size(): number; } export default TTLMap;