UNPKG

@maximai/maxim-js

Version:

Maxim AI JS SDK. Visit https://getmaxim.ai for more info.

38 lines 1.05 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); class ExpiringKeyValueStore { constructor() { this.store = new Map(); } set(key, value, expirySeconds) { const expiryTime = Date.now() + expirySeconds * 1000; this.store.set(key, [value, expiryTime]); this.evictExpired(); } get(key) { const entry = this.store.get(key); if (entry) { const [value, expiryTime] = entry; if (Date.now() < expiryTime) { return value; } else { this.store.delete(key); } } return null; } delete(key) { this.store.delete(key); } evictExpired() { const currentTime = Date.now(); for (const [key, [, expiryTime]] of this.store) { if (currentTime >= expiryTime) { this.store.delete(key); } } } } exports.default = ExpiringKeyValueStore; //# sourceMappingURL=expiringKeyValueStore.js.map