UNPKG

@naturalcycles/db-lib

Version:

Lowest Common Denominator API to supported Databases

25 lines (24 loc) 894 B
import { AsyncMemoCache, MISS, NumberOfSeconds } from '@naturalcycles/js-lib'; import { CommonKeyValueDao } from './commonKeyValueDao'; 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>; }