UNPKG

@maximai/maxim-js-langchain

Version:

This is the langchain wrapper built for (Maxim JS SDK)[https://www.npmjs.com/package/@maximai/maxim-js].

41 lines (40 loc) 1.13 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(); const expiredKeys = []; this.store.forEach((value, key) => { const [, expiryTime] = value; if (currentTime >= expiryTime) { expiredKeys.push(key); } }); expiredKeys.forEach((key) => this.store.delete(key)); } } exports.default = ExpiringKeyValueStore;