@naturalcycles/db-lib
Version:
Lowest Common Denominator API to supported Databases
27 lines (26 loc) • 1.01 kB
TypeScript
import type { AsyncMemoCache } from '@naturalcycles/js-lib/decorators';
import type { NumberOfSeconds } from '@naturalcycles/js-lib/types';
import { MISS } from '@naturalcycles/js-lib/types';
import type { CommonKeyValueDao } from './commonKeyValueDao.js';
export interface CommonKeyValueDaoMemoCacheCfg<VALUE> {
dao: CommonKeyValueDao<string, VALUE>;
/**
* If set, every `set()` will set `expireAt` (TTL) option.
*/
ttl?: NumberOfSeconds;
}
/**
* AsyncMemoCache implementation, backed by CommonKeyValueDao.
*
* Does NOT support persisting Errors, skips them instead.
*
* Also, does not support .clear(), as it's more dangerous than useful to actually
* clear the whole table/cache.
*/
export declare class CommonKeyValueDaoMemoCache<VALUE> implements AsyncMemoCache<string, VALUE> {
private cfg;
constructor(cfg: CommonKeyValueDaoMemoCacheCfg<VALUE>);
get(k: string): Promise<VALUE | typeof MISS>;
set(k: string, v: VALUE): Promise<void>;
clear(): Promise<void>;
}