UNPKG

npmplus-mcp-server

Version:

Production-ready MCP server for intelligent JavaScript package management. Works with Claude, Windsurf, Cursor, VS Code, and any MCP-compatible AI editor.

69 lines 2.35 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.cache = exports.CacheManager = void 0; const node_cache_1 = __importDefault(require("node-cache")); const constants_js_1 = require("./constants.js"); class CacheManager { memoryCache; constructor() { // Memory cache with different TTLs for different data types this.memoryCache = new node_cache_1.default({ stdTTL: constants_js_1.CACHE_SETTINGS.SHORT_TTL, checkperiod: constants_js_1.CACHE_SETTINGS.CHECK_PERIOD }); } // Get value from cache async get(key) { try { return this.memoryCache.get(key); } catch (error) { console.error(`Cache get error for key ${key}:`, error); return undefined; } } // Set value in cache with optional TTL async set(key, value, ttl) { try { return this.memoryCache.set(key, value, ttl || constants_js_1.CACHE_SETTINGS.SHORT_TTL); } catch (error) { console.error(`Cache set error for key ${key}:`, error); return false; } } // Delete from cache async del(key) { try { return this.memoryCache.del(key) > 0; } catch (error) { console.error(`Cache delete error for key ${key}:`, error); return false; } } // Clear all cache async flush() { this.memoryCache.flushAll(); } // Get cache stats getStats() { return this.memoryCache.getStats(); } // Cache key generators for consistency static keys = { packageInfo: (name, version) => `pkg:${name}${version ? `@${version}` : ''}`, searchResults: (query, limit) => `search:${query}:${limit || 25}`, vulnerabilities: (name, version) => `vuln:${name}@${version}`, bundleSize: (name, version) => `bundle:${name}@${version}`, downloads: (name, period) => `downloads:${name}:${period}`, dependencies: (path) => `deps:${path}` }; } exports.CacheManager = CacheManager; // Global cache instance exports.cache = new CacheManager(); //# sourceMappingURL=cache.js.map