happn-3
Version:
pub/sub api as a service using primus and mongo & redis or nedb, can work as cluster, single process or embedded using nedb
40 lines (32 loc) • 734 B
JavaScript
module.exports = class StaticCache extends require('./cache-base') {
#cache;
constructor(name, opts) {
super(name, opts);
this.#cache = {};
}
getInternal(key) {
return this.#cache[key];
}
setInternal(key, data) {
this.#cache[key] = data;
if (typeof data.ttl === 'number' && data.ttl !== Infinity) {
this.appendTimeout(key, data.ttl);
}
}
removeInternal(key) {
this.clearTimeout(key);
delete this.#cache[key];
}
valuesInternal() {
return Object.values(this.#cache).map((item) => item.data);
}
keysInternal() {
return Object.keys(this.#cache);
}
hasInternal(key) {
return this.#cache[key] != null;
}
clearInternal() {
this.#cache = {};
}
};