@thermopylae/lib.cache
Version:
28 lines (26 loc) • 1.21 kB
TypeScript
import { UnixTimestamp } from '@thermopylae/core.declarations';
import { EntryExpiredCallback, ExpirableEntry, GarbageCollector } from './interface';
/**
* {@link GarbageCollector} implementation which uses a map of buckets to keep entries that needs to be evicted. <br/>
* Each timestamp has an according bucket with entries that need to be evicted at that time. <br/>
* A timer is set to tick on each second and evicts all entries from the bucket corresponding to timestamp when timer fired.
*
* @template T Type of the cache entry.
*/
declare class BucketGarbageCollector<T extends ExpirableEntry> implements GarbageCollector<T> {
private static readonly EVICTION_TIMEOUT;
private readonly buckets;
private readonly evictionTimer;
private entryExpiredCb;
constructor(entryExpiredCb?: EntryExpiredCallback<T>);
get idle(): boolean;
get size(): number;
manage(entry: T): void;
update(oldExpiration: UnixTimestamp, entry: T): void;
leave(entry: T): void;
clear(): void;
setEntryExpiredCallback(cb: EntryExpiredCallback<T>): void;
private evictionTimerHandler;
private static defaultEntryExpiredCallback;
}
export { BucketGarbageCollector };