UNPKG

@superadnim/osint-mcp-server

Version:

Professional OSINT MCP Server for intelligence gathering with privacy protection

107 lines 3.31 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.CacheManager = void 0; const node_cache_1 = __importDefault(require("node-cache")); class CacheManager { cache; defaultTTL; constructor(options = {}) { this.defaultTTL = options.ttl || 300; // 5 minutes default this.cache = new node_cache_1.default({ stdTTL: this.defaultTTL, checkperiod: options.checkperiod || 60, useClones: false, }); } set(key, value, ttl) { return this.cache.set(key, value, ttl || this.defaultTTL); } get(key) { return this.cache.get(key); } has(key) { return this.cache.has(key); } del(key) { return this.cache.del(key); } clear() { this.cache.flushAll(); } keys() { return this.cache.keys(); } stats() { return this.cache.getStats(); } generateKey(prefix, params) { const sortedParams = Object.keys(params) .sort() .reduce((result, key) => { result[key] = params[key]; return result; }, {}); const paramString = JSON.stringify(sortedParams); return `${prefix}:${Buffer.from(paramString).toString('base64')}`; } memoize(fn, keyGenerator, ttl) { return (async (...args) => { const key = keyGenerator(...args); if (this.has(key)) { return this.get(key); } const result = await fn(...args); this.set(key, result, ttl); return result; }); } async getOrSet(key, fetchFn, ttl) { if (this.has(key)) { return this.get(key); } const result = await fetchFn(); this.set(key, result, ttl); return result; } setWithTags(key, value, tags, ttl) { const success = this.set(key, value, ttl); if (success) { // Store tag associations for (const tag of tags) { const tagKey = `tag:${tag}`; const taggedKeys = this.get(tagKey) || []; if (!taggedKeys.includes(key)) { taggedKeys.push(key); this.set(tagKey, taggedKeys, ttl); } } } return success; } deleteByTag(tag) { const tagKey = `tag:${tag}`; const taggedKeys = this.get(tagKey) || []; let deletedCount = 0; for (const key of taggedKeys) { deletedCount += this.del(key); } this.del(tagKey); return deletedCount; } createInvestigationCache() { const investigationCache = new CacheManager({ ttl: 3600, // 1 hour for investigation data checkperiod: 300, // Check every 5 minutes }); // Set up automatic cleanup when investigation expires setTimeout(() => { investigationCache.clear(); }, 7 * 24 * 60 * 60 * 1000); // 7 days return investigationCache; } } exports.CacheManager = CacheManager; //# sourceMappingURL=cache-manager.js.map