@thermopylae/lib.cache
Version:
62 lines (61 loc) • 1.91 kB
TypeScript
import { Undefinable } from '@thermopylae/core.declarations';
import { CacheBackend } from '../contracts/cache-backend';
import { CacheEntry } from '../contracts/commons';
/**
* Backend which has a pool of reusable {@link CacheEntry}. Pool can have a fixed or dynamic size.
* If pool has a fixed size, trying to insert keys above that size will result in an error. <br/>
* Each time *key* is inserted, a free {@link CacheEntry} is taken from pool to hold the *value*.
* When *key* is deleted/expires/cleared, it's according {@link CacheEntry} is returned to pool and can be used by another *key*.
*
* @template Key Type of the *key*.
* @template Value Type of the *value*.
* @template Entry Type of the cache entry. <br/>
* Defaults to {@link CacheEntry}.
*/
declare class EntryPoolCacheBackend<Key, Value, Entry extends CacheEntry<Key, Value> = CacheEntry<Key, Value>> implements CacheBackend<Key, Value> {
private readonly store;
private readonly entryPool;
/**
* @param capacity Backend capacity. <br/>
* When given, cache will not grow above *capacity* (i.e. will have a fixed size). <br/>
* If you omit this argument, backend will have a dynamic size.
*/
constructor(capacity?: number);
/**
* @inheritDoc
*/
get(key: Key): Undefinable<Entry>;
/**
* @inheritDoc
*/
has(key: Key): boolean;
/**
* @inheritDoc
*/
set(key: Key, value: Value): Entry;
/**
* @inheritDoc
*/
del(entry: Entry): void;
/**
* @inheritDoc
*/
clear(): void;
/**
* @inheritDoc
*/
get size(): number;
/**
* @inheritDoc
*/
[Symbol.iterator](): IterableIterator<[Key, Entry]>;
/**
* @inheritDoc
*/
keys(): IterableIterator<Key>;
/**
* @inheritDoc
*/
values(): IterableIterator<Entry>;
}
export { EntryPoolCacheBackend };