@thermopylae/lib.cache
Version:
49 lines (48 loc) • 2.4 kB
TypeScript
import { Seconds, UnixTimestamp } from '@thermopylae/core.declarations';
import { EntryValidity } from '../../contracts/cache-replacement-policy';
import { AbstractExpirationPolicy, ExpirableCacheEntry } from './abstract';
interface AbsoluteExpirationPolicyArgumentsBundle {
/**
* Time to live for `key` in seconds. <br>
* When inserting the key, use {@link INFINITE_EXPIRATION} or omit this option to specify that the key should not expire. <br/>
* -----------------------------------------------------
* When ttl is updated, depending on the value of `expiresAfter` param, following behaviours will occur: <br/>
*
* Value | Behaviour
* ---------------------------- | -------------------------------
* `undefined` | Entry ttl won't be updated and will remain the same.
* {@link INFINITE_EXPIRATION} | Entry ttl is discarded, so that it will never expire.
* ttl of old value | Entry ttl won't be updated and will remain the same. Notice that timer is not reset, meaning that if old value remains to live `x` seconds, it will be evicted after `x` seconds.
* ttl different from old value | Entry ttl will be updated to the new ttl. Timer will be reset, so that new value remains to live `expiresAfter` seconds.
*/
expiresAfter?: Seconds;
/**
* Timestamp from when ttl starts counting in seconds as Unix Timestamp. <br/>
* Defaults to current unix timestamp when `expiresAfter` is given.
*/
expiresFrom?: UnixTimestamp;
}
/**
* @private
*/
declare abstract class AbsoluteExpirationPolicy<Key, Value, ArgumentsBundle extends AbsoluteExpirationPolicyArgumentsBundle> extends AbstractExpirationPolicy<Key, Value, ArgumentsBundle> {
/**
* @inheritDoc
*/
onHit(entry: ExpirableCacheEntry<Key, Value>): EntryValidity;
/**
* @inheritDoc
*/
onSet(entry: ExpirableCacheEntry<Key, Value>, options?: ArgumentsBundle): void;
/**
* @inheritDoc
*/
onUpdate(entry: ExpirableCacheEntry<Key, Value>, options?: ArgumentsBundle): void;
/**
* @inheritDoc
*/
onClear(): void;
protected evictIfExpired(entry: ExpirableCacheEntry<Key, Value>): EntryValidity;
protected static isNonExpirable(argumentsBundle: AbsoluteExpirationPolicyArgumentsBundle): boolean;
}
export { AbsoluteExpirationPolicy, AbsoluteExpirationPolicyArgumentsBundle };