import { ArCacheInterface } from '../faces/utils/arCache'; /** * Implementation of a simple in-memory cache. */ export default class ArCache implements ArCacheInterface { private _cache; private _size; private _maxMemSize; private _itemsToDelete; private _defaultTtl; get size(): number; get memSize(): number; /** * @param {number=0} ttl - Time to live in seconds, Default 0 (never). * @param {number=2e+6} maxMemSize - Maximum memory size in bytes, default is 2MB. * @param {number=3} itemsToDelete - Number of items to delete when cache is full. */ constructor(ttl?: number, maxMemSize?: number, itemsToDelete?: number); /** * Add a new item to the cache. * @param {string} key * @param {any} value * @param {number} ttl - Time to live in seconds, 0 or null means never expires. * @returns {Promise} */ set(key: string, value: any, ttl?: number): Promise; /** * Get a specific item from the cache. * @param {string} key * @returns {any} */ get(key: string): Promise; /** * Delete a specific item from the cache. * @param {string} key */ del(key: string): void; /** * Clear the cache. */ clear(): void; /** * Check wether an item has expired. * @param {string} key * @returns boolean */ hasExpired(key: string): boolean; /** * Delete old stored data from cache when the maxMemSize is reached to make room for new content. * @private */ private makeRoom; /** * Get the rough size of the cache. * @param {object} obj * @private */ private roughSizeof; }