@thermopylae/lib.cache
Version:
56 lines (55 loc) • 2.05 kB
TypeScript
import { Seconds } from '@thermopylae/core.declarations';
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 on the next {@link Cache.get} operation. <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 SlidingReactiveExpirationPolicy<Key, Value, ArgumentsBundle extends SlidingExpirationPolicyArgsBundle = SlidingExpirationPolicyArgsBundle> extends AbstractExpirationPolicy<Key, Value, ArgumentsBundle> {
/**
* @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 static storeExpirationMetadata;
private static isNonExpirable;
}
export { SlidingReactiveExpirationPolicy, SlidingExpirationPolicyArgsBundle, ExpirableSlidingCacheEntry, TIME_SPAN_SYM };