UNPKG

@thermopylae/lib.cache

Version:
52 lines (51 loc) 1.93 kB
import { AbsoluteExpirationPolicy, AbsoluteExpirationPolicyArgumentsBundle } from './absolute'; import { EntryValidity } from '../../contracts/cache-replacement-policy'; import { GarbageCollector } from '../../garbage-collectors/interface'; import { ExpirableCacheEntry } from './abstract'; /** * Expiration policy which evicts keys on it's behalf in the background. <br/> * Expired keys are tracked with the help of {@link GarbageCollector}, which evicts them asynchronously when they expire. <br/> * This kind of policy can be used if you have keys that won't be often queried * and you need a background timer which evicts keys as soon as they expire. * * @template Key Type of the key. * @template Value Type of the value. * @template ArgumentsBundle Type of the arguments bundle. */ declare class ProactiveExpirationPolicy<Key, Value, ArgumentsBundle extends AbsoluteExpirationPolicyArgumentsBundle = AbsoluteExpirationPolicyArgumentsBundle> extends AbsoluteExpirationPolicy<Key, Value, ArgumentsBundle> { private readonly gc; /** * @param gc {@link GarbageCollector} which notifies about expired entries. <br/> * Defaults to {@link HeapGarbageCollector}. */ constructor(gc?: GarbageCollector<any>); /** * Get the number of tracked for expiration keys. */ get size(): number; /** * @inheritDoc */ onHit(): EntryValidity; /** * @inheritDoc */ onSet(entry: ExpirableCacheEntry<Key, Value>, options?: ArgumentsBundle): void; /** * @inheritDoc */ onUpdate(entry: ExpirableCacheEntry<Key, Value>, options?: ArgumentsBundle): void; /** * @inheritDoc */ onDelete(entry: ExpirableCacheEntry<Key, Value>): void; /** * @inheritDoc */ onClear(): void; /** * **Method used for unit testing purposes!** */ isIdle(): boolean; } export { ProactiveExpirationPolicy };