@melchyore/adonis-cache
Version:
Cache package for AdonisJS V5
45 lines (43 loc) • 1.25 kB
JavaScript
;
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;