@devabdultech/hn-mcp-server
Version:
MCP Server for using the Hacker News API
35 lines • 837 B
JavaScript
export class Cache {
ttlMs;
cache = new Map();
constructor(ttlMs = 5 * 60 * 1000) {
this.ttlMs = ttlMs;
}
get(key) {
const item = this.cache.get(key);
if (!item) {
return undefined;
}
if (Date.now() > item.expiry) {
this.cache.delete(key);
return undefined;
}
return item.value;
}
set(key, value) {
this.cache.set(key, {
value,
expiry: Date.now() + this.ttlMs,
});
}
delete(key) {
this.cache.delete(key);
}
clear() {
this.cache.clear();
}
}
export const storyCache = new Cache();
export const commentCache = new Cache();
export const userCache = new Cache();
export const searchCache = new Cache(60 * 1000);
//# sourceMappingURL=cache.js.map