docfs
Version:
MCP server for accessing local file system content with intelligent search and listing tools
39 lines • 1.03 kB
JavaScript
export class LRUCache {
maxSize;
ttl;
cache = new Map();
constructor(maxSize, ttl) {
this.maxSize = maxSize;
this.ttl = ttl;
}
get(key) {
const entry = this.cache.get(key);
if (!entry)
return undefined;
if (Date.now() > entry.expires) {
this.cache.delete(key);
return undefined;
}
// refresh LRU order
this.cache.delete(key);
this.cache.set(key, entry);
return entry.value;
}
set(key, value) {
const entry = { value, expires: Date.now() + this.ttl };
if (this.cache.has(key)) {
this.cache.delete(key);
}
this.cache.set(key, entry);
if (this.cache.size > this.maxSize) {
const firstKey = this.cache.keys().next().value;
if (firstKey !== undefined) {
this.cache.delete(firstKey);
}
}
}
clear() {
this.cache.clear();
}
}
//# sourceMappingURL=cache.js.map