ps2census
Version:
Client to connect to the PS2 Event Stream websocket.
32 lines • 881 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.LocalCache = exports.LocalCacheOptions = void 0;
class LocalCacheOptions {
}
exports.LocalCacheOptions = LocalCacheOptions;
class LocalCache {
constructor(options) {
this.cache = new Map();
this.maxEntries = options?.maxEntries ?? 1000;
}
async put(key, data) {
if (!this.cache.has(key) && this.cache.size >= this.maxEntries)
this.pruneOldest();
this.cache.set(key, data);
}
async fetch(key) {
return this.cache.get(key) ?? null;
}
async forget(key) {
this.cache.delete(key);
}
async forgetAll() {
this.cache.clear();
}
pruneOldest() {
const [[key]] = this.cache;
this.cache.delete(key);
}
}
exports.LocalCache = LocalCache;
//# sourceMappingURL=local.cache.js.map