UNPKG

@dr.pogodin/react-utils

Version:

Collection of generic ReactJS components and utils

29 lines (28 loc) 769 B
/** * Implements the static cache. */ export default class Cache<DatumT> { private maxSize; private items; private size; constructor(maxSize: number); /** * Cache lookup. * @param key Item key to look for. * @param [maxage=Number.MAX_VALUE] Optional. The maximum age of * cached item to serve. Default to infinite. * @returns Cached item, or null if the item is absent in cache, * or stale. */ get({ key, maxage, }: { key: string; maxage?: number; }): DatumT | null; /** * Adds item to cache. * @param data Item to add. * @param key Key to store the item at. * @param size Byte size of the item. */ add(data: DatumT, key: string, size: number): void; }