/** @hidden */ export declare class Entry { key: Key; value: Value; size: number; newer: Entry | null; older: Entry | null; constructor(key: Key, value: Value, size: number, newer: Entry | null, older: Entry | null); } /** * Fixed size cache that evicts its entries in least-recently-used order when it overflows. * Modeled after standard JavaScript `Map` otherwise. */ export declare class LRUCache { /** * Optional callback that is called on every item that is evicted from the cache. * * **Note**: This callback is not called when an item is explicitly deleted from the map via * [[delete]] or [[clear]]. */ evictionCallback?: (key: Key, value: Value) => void; /** * Optional callback that is called on every item that should be evicted from the cache to * determine if it can be removed, or should be locked in the cache. * * It returns `true` if the item can be removed from cache, `false` otherwise. Locking items in * the cache should be a temporary measure, since if the cache is filled with non-evictable * items only, it may grow beyond its capacity. * * **Note**: This callback is not called when an item is explicitly deleted from the map via * [[delete]] or [[clear]]. */ canEvict?: (key: Key, value: Value) => boolean; private m_capacity; private m_size; /** * The internal map object that keeps the key-value pairs and their order. */ private readonly m_map; /** * The newest entry, i.e. the most recently used item. */ private m_newest; /** * The oldest entry, i.e. the least recently used item. */ private m_oldest; /** * A function determining the size per element. */ private m_sizeFunction; /** * Creates a new instance of `LRUCache`. * * The optional [[sizeFunction]] can be used to fine tune the memory consumption of all cached * elements, thus [[cacheCapacity]] means then memory used (in MBs). Otherwise, if * [[sizeFunction]] is not specified, the [[cacheCapacity]] accounts for the maximum * number of elements stored. * * @param cacheCapacity - Number used to configure the maximum cache size, may express * number of entries or memory consumed in megabytes depending on [[sizeFunction]]. * @param sizeFunction - A function determining the size per element. */ constructor(cacheCapacity: number, sizeFunction?: (v: Value) => number); /** * Iterates over all items from the most recently used item to the least recently used one. * * **Note**: Results are undefined if the entire cache is modified during iteration. You may * although modify the current element in [[callbackfn]] function. * * @param callbackfn - The callback to call for each item. * @param thisArg - Optional this argument for the callback. */ forEach(callbackfn: (value: Value, key: Key, map: LRUCache) => void, thisArg?: any): void; /** * The size of the cache, i.e. the sum of all the sizes of all the objects in the cache. * * @returns The size of the cache. */ get size(): number; /** * Returns the maximum capacity of the cache, i.e. the maximum number of elements this cache * can contain or the total amount of memory that may be consumed by cache if element size * function was specified in cache c-tor. * * @returns The capacity of the cache. */ get capacity(): number; /** * @deprecated - DO NOT USE. Will be removed in future versions. * * Returns the internal map object that keeps the key-value pairs and their order. * * @returns The internal map object. */ get map(): Map>; /** * Returns the newest entry in the cache. * * @returns Newest entry in the cache. */ get newest(): Entry | null; /** * Returns the oldest entry in the cache. * * Note: Does not promote the oldest item as most recently used item. * * @returns Oldest entry in the cache. */ get oldest(): Entry | null; /** * Resets the capacity of this cache. If `newCapacity` is smaller than the current cache size, * all items will be evicted until the cache shrinks to `newCapacity`. * * @param newCapacity - The new capacity of this cache. */ setCapacity(newCapacity: number): void; /** * Resets the cache capacity and function used to measure the element size. * * @param newCapacity - The new capacity masured in units returned from [[sizeMeasure]] funtion. * @param sizeMeasure - Function that defines the size of element, if you want to measure * number of elements only always return 1 from this function (default), you may also * specify own function that measures entries by memory consumed, nubmer of sub-elements, etc. */ setCapacityAndMeasure(newCapacity: number, sizeMeasure?: (v: Value) => number): void; /** * Updates the size of all elements in this cache. If their aggregated size is larger than the * capacity, items will be evicted until the cache shrinks to fit the capacity. */ shrinkToCapacity(): void; /** * Inserts or updates a key/value pair in the cache. * * If the key already existed in the cache, it will be updated and promoted to the most recently * used item. * * If the key didn't exist in the cache, it will be inserted as most recently used item. An * eviction of the least recently used item takes place if the cache exceeded its capacity. * * @param key - The key for the key-value pair to insert or update. * @param value - The value for the key-value pair to insert or update. */ set(key: Key, value: Value): void; /** * Looks up key in the cache and returns the associated value. * * @param key - The key to look up. * @returns The associated value, or `undefined` if the key-value pair is not in the cache. */ get(key: Key): Value | undefined; /** * Test if a key/value pair is in the cache. * * @param key - The key to look up. * @returns `true` if the key-value pair is in the cache, `false` otherwise. */ has(key: Key): boolean; /** * Clears the cache and removes all stored key-value pairs. * * Does not call the eviction callback. Use [[evictAll]] to clear the cache and call the * eviction callback. */ clear(): void; /** * Evicts all items from the cache, calling the eviction callback on each item. * * Use [[clear]] to remove all items without calling the eviction callback. */ evictAll(): void; /** * Evict selected elements from the cache using [[selector]] function. * * @param selector - The function for selecting elements for eviction. * @param thisArg - Optional _this_ object reference. */ evictSelected(selector: (value: Value, key: Key) => boolean, thisArg?: any): void; /** * Explicitly removes a key-value pair from the cache. * * **Note**: This is an explicit removal, thus, the eviction callback will not be called. * * @param key - The key of the key-value pair to delete. * @returns `true` if the key-value pair existed and was deleted, `false` otherwise. */ delete(key: Key): boolean; protected evict(): void; protected evictOldest(): Entry | undefined; private deleteEntry; private promoteEntry; } //# sourceMappingURL=LRUCache.d.ts.map