UNPKG

@goatlab/fluent

Version:

Readable query Interface & API generator for TS and Node

44 lines (43 loc) 1.12 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Cache = void 0; const tslib_1 = require("tslib"); const keyv_1 = tslib_1.__importDefault(require("keyv")); class Cache extends keyv_1.default { async has(key) { const value = await this.get(key); return value ? true : false; } async remember(key, ms, fx) { const value = await this.get(key); if (value) { return value; } const result = await fx(); await this.set(key, result, ms); return result; } async rememberForever(key, fx) { const value = await this.get(key); if (value) { return value; } const result = await fx(); await this.set(key, result); return result; } async pull(key) { const value = await this.get(key); if (value) { this.delete(key); } return value; } async forget(key) { return await this.delete(key); } async flush() { return await this.clear(); } } exports.Cache = Cache;