UNPKG

@melchyore/adonis-cache

Version:
45 lines (43 loc) 1.25 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const luxon_1 = require("luxon"); class BaseStore { constructor() { } setPrefix(prefix) { this.prefixKey = prefix; } get prefix() { return this.prefixKey; } calculateTTL(ttlInMilliseconds) { return ttlInMilliseconds; } /*protected removePrefixFromKey (key: string): string { if (key.startsWith(this.prefixKey)) { return key.replace(this.prefixKey, '') } return key }*/ buildKey(key) { return `${this.prefix}${key}`; } serialize(value) { return JSON.stringify(value); } deserialize(value) { return JSON.parse(value); } isStaleRecord(record) { const expiration = record.expiration; if (expiration) { if (typeof expiration === 'number') { return expiration !== 0 && luxon_1.DateTime.now().toMillis() >= expiration; } else { return luxon_1.DateTime.now().toMillis() >= luxon_1.DateTime.fromJSDate(expiration).toMillis(); } } return false; } } exports.default = BaseStore;