UNPKG

@thermopylae/lib.cache

Version:
71 lines (70 loc) 2.43 kB
import { Seconds } from '@thermopylae/core.declarations'; import { GarbageCollector } from '../../garbage-collectors/interface'; import { AbstractExpirationPolicy, ExpirableCacheEntry } from './abstract'; import { EntryValidity } from '../../contracts/cache-replacement-policy'; /** * @private */ declare const TIME_SPAN_SYM: unique symbol; /** * @private */ interface ExpirableSlidingCacheEntry<Key, Value> extends ExpirableCacheEntry<Key, Value> { [TIME_SPAN_SYM]?: Seconds; } interface SlidingExpirationPolicyArgsBundle { /** * Time span identifies how long the data should remain in the cache * after the data was last accessed. */ timeSpan?: Seconds; } /** * Expiration policy which evicts keys based on time span access. <br/> * If key wasn't accessed in the specified {@link SlidingExpirationPolicyArgsBundle.timeSpan}, * it will be evicted by {@link GarbageCollector} in the background. <br/> * If key was accessed in that time span, it's expiration time will be increased with the value of time span. * * @template Key Type of the key. * @template Value Type of the value. * @template ArgumentsBundle Type of the arguments bundle. */ declare class SlidingProactiveExpirationPolicy<Key, Value, ArgumentsBundle extends SlidingExpirationPolicyArgsBundle = SlidingExpirationPolicyArgsBundle> extends AbstractExpirationPolicy<Key, Value, ArgumentsBundle> { /** * @private */ private readonly gc; constructor(gc?: GarbageCollector<any>); /** * Get the number of tracked for expiration keys. */ get size(): number; /** * Check whether GC is idle. */ get idle(): boolean; /** * @inheritDoc */ onHit(entry: ExpirableSlidingCacheEntry<Key, Value>): EntryValidity; /** * @inheritDoc */ onSet(entry: ExpirableSlidingCacheEntry<Key, Value>, options?: ArgumentsBundle): void; /** * @inheritDoc */ onUpdate(entry: ExpirableSlidingCacheEntry<Key, Value>, options?: ArgumentsBundle): void; /** * @inheritDoc */ onDelete(entry: ExpirableSlidingCacheEntry<Key, Value>): void; /** * @inheritDoc */ onClear(): void; private scheduleEviction; private static storeExpirationMetadata; private static isNonExpirable; } export { SlidingProactiveExpirationPolicy, ExpirableSlidingCacheEntry, SlidingExpirationPolicyArgsBundle, TIME_SPAN_SYM };