Project Files
dist / cache.js
"use strict";
// Tiny in-process LRU + TTL cache. No deps, no disk. Resets when the
// LM Studio plugin worker (or the MCP server process) restarts.
Object.defineProperty(exports, "__esModule", { value: true });
exports.TtlLruCache = void 0;
class TtlLruCache {
constructor(maxEntries, ttlMs) {
this.maxEntries = maxEntries;
this.ttlMs = ttlMs;
this.map = new Map();
}
get(key) {
const e = this.map.get(key);
if (!e)
return undefined;
if (Date.now() > e.expiresAt) {
this.map.delete(key);
return undefined;
}
// Refresh LRU position.
this.map.delete(key);
this.map.set(key, e);
return e.value;
}
set(key, value) {
if (this.ttlMs <= 0)
return; // caching disabled
if (this.map.has(key))
this.map.delete(key);
this.map.set(key, { value, expiresAt: Date.now() + this.ttlMs });
while (this.map.size > this.maxEntries) {
const oldest = this.map.keys().next().value;
if (oldest === undefined)
break;
this.map.delete(oldest);
}
}
clear() {
this.map.clear();
}
get size() {
return this.map.size;
}
}
exports.TtlLruCache = TtlLruCache;
//# sourceMappingURL=cache.js.map