mushcode-mcp-server
Version:
A specialized Model Context Protocol server for MUSHCODE development assistance. Provides AI-powered code generation, validation, optimization, and examples for MUD development.
74 lines • 1.94 kB
JavaScript
/**
* Simple caching utilities for performance optimization
*/
export class SimpleCache {
cache = new Map();
maxSize;
defaultTtl;
constructor(maxSize = 1000, defaultTtl) {
this.maxSize = maxSize;
if (defaultTtl !== undefined) {
this.defaultTtl = defaultTtl;
}
}
get(key) {
const entry = this.cache.get(key);
if (!entry)
return undefined;
// Check TTL
if (entry.ttl && Date.now() - entry.timestamp > entry.ttl) {
this.cache.delete(key);
return undefined;
}
return entry.value;
}
set(key, value, ttl) {
// Evict if at capacity
if (this.cache.size >= this.maxSize) {
const firstKey = this.cache.keys().next().value;
if (firstKey) {
this.cache.delete(firstKey);
}
}
const entry = {
value,
timestamp: Date.now(),
...(ttl && { ttl }),
...(!ttl && this.defaultTtl && { ttl: this.defaultTtl })
};
this.cache.set(key, entry);
}
has(key) {
return this.get(key) !== undefined;
}
delete(key) {
return this.cache.delete(key);
}
clear() {
this.cache.clear();
}
size() {
return this.cache.size;
}
}
export class SimpleCacheManager {
caches = new Map();
getCache(name, maxSize, defaultTtl) {
if (!this.caches.has(name)) {
this.caches.set(name, new SimpleCache(maxSize, defaultTtl));
}
return this.caches.get(name);
}
clearAll() {
for (const cache of this.caches.values()) {
cache.clear();
}
}
destroy() {
this.clearAll();
this.caches.clear();
}
}
// Global simple cache manager
export const simpleCacheManager = new SimpleCacheManager();
//# sourceMappingURL=simple-cache.js.map