UNPKG

@thermopylae/lib.cache

Version:
47 lines (46 loc) 1.98 kB
import { Threshold } from '@thermopylae/core.declarations'; import { BaseLFUEvictionPolicy, EvictableCacheEntry } from './lfu-base'; import { CacheBackendElementsCount } from '../../contracts/cache-backend'; /** * Determine size of an object in Bytes. This object is the actual entry stored in the cache. <br/> * That entry contains key, value and other metadata. <br/> * While computing it's size, you are not allowed to alter it's values/structure. */ interface SizeOf<T> { (object: Readonly<T>): number; } /** * [Greedy Dual-Size with Frequency](https://www.hpl.hp.com/personal/Lucy_Cherkasova/projects/gdfs.html "Improving Web Servers and Proxies Performance with GDSF Caching Policies") eviction policy. * **To be used carefully, as in practice, if no items are evicted, items frequency will increase with a very low rate.** * * @template Key Type of the key. * @template Value Type of the value. * @template ArgumentsBundle Type of the arguments bundle. */ declare class GDSFEvictionPolicy<Key, Value, ArgumentsBundle> extends BaseLFUEvictionPolicy<Key, Value, ArgumentsBundle> { private readonly sizeOf; private cacheAge; /** * @param cacheMaxCapacity {@link Cache} maximum capacity. * @param cacheBackendElementsCount Cache backend elements count. * @param sizeOfInBytes Function which computes sizeof cache entry in bytes. */ constructor(cacheMaxCapacity: Threshold, cacheBackendElementsCount: CacheBackendElementsCount, sizeOfInBytes?: SizeOf<Value>); /** * @inheritDoc */ onUpdate(entry: EvictableCacheEntry<Key, Value>): void; /** * @inheritDoc */ protected get initialFrequency(): number; /** * @inheritDoc */ protected computeEntryFrequency(entry: EvictableCacheEntry<Key, Value>, entryScore: number): number; /** * @inheritDoc */ protected onEvict(frequencyOfTheEvictedEntry: number): void; } export { GDSFEvictionPolicy };