@m4x1m1l14n/cache
Version:
Lightweight in-memory isomorphic cache implementation with TTL for browser & Node JS written in TypeScript
32 lines (31 loc) • 976 B
TypeScript
import { CacheOptions } from '../models/CacheOptions';
import { ExpirationCallback } from '../types';
export declare class Cache<K, T> {
private options;
private cache;
constructor(options?: CacheOptions);
set(key: K, value: T, ttl?: number, callback?: ExpirationCallback<T>): Cache<K, T>;
/**
* Returns value by its key
*
* @param key Key of value to get
* @param refresh True to refresh item TTL or false to not
*/
get(key: K, refresh?: boolean): T | undefined;
/**
* Takes value by its key from cache.
*
* Value is returned and key is removed from cache.
*
* @param key Key to take
* @returns Value of specified key
*/
take(key: K): T | undefined;
has(key: K): boolean;
delete(key: K): boolean;
mdelete(keys: K[]): Cache<K, T>;
get size(): number;
forEach(cb: (value: T, key: K) => void): void;
private cleanup;
flush(invokeCallback?: boolean): void;
}