UNPKG

@thermopylae/lib.cache

Version:
57 lines (56 loc) 1.89 kB
import { DoublyLinkedListNode } from '../../data-structures/list/doubly-linked'; import { CacheReplacementPolicy, EntryValidity, Deleter } from '../../contracts/cache-replacement-policy'; import { CacheEntry } from '../../contracts/commons'; import { CacheBackendElementsCount } from '../../contracts/cache-backend'; /** * @private */ interface EvictableCacheEntry<Key, Value> extends CacheEntry<Key, Value>, DoublyLinkedListNode<EvictableCacheEntry<Key, Value>> { } /** * [Least Recently Used](https://en.wikipedia.org/wiki/Cache_replacement_policies#Least_recently_used_(LRU) "Least recently used (LRU)") eviction policy. * * @template Key Type of the key. * @template Value Type of the value. * @template ArgumentsBundle Type of the arguments bundle. */ declare class LRUEvictionPolicy<Key, Value, ArgumentsBundle> implements CacheReplacementPolicy<Key, Value, ArgumentsBundle> { private readonly cacheMaxCapacity; private readonly cacheBackendElementsCount; private deleteFromCache; private usageRecency; /** * @param cacheMaxCapacity {@link Cache} maximum capacity. * @param cacheBackendElementsCount Cache backend elements count. */ constructor(cacheMaxCapacity: number, cacheBackendElementsCount: CacheBackendElementsCount); /** * @inheritDoc */ onHit(entry: EvictableCacheEntry<Key, Value>): EntryValidity; /** * @inheritDoc */ onMiss(): void; /** * @inheritDoc */ onSet(entry: EvictableCacheEntry<Key, Value>): void; /** * @inheritDoc */ onUpdate(): void; /** * @inheritDoc */ onDelete(entry: EvictableCacheEntry<Key, Value>): void; /** * @inheritDoc */ onClear(): void; /** * @inheritDoc */ setDeleter(deleter: Deleter<Key, Value>): void; } export { LRUEvictionPolicy, EvictableCacheEntry };