import NodeCache from 'node-cache'; const cache = new NodeCache({ stdTTL: 345600, checkperiod: 3600, useClones: false }); function scaleCache() { const mem = process.memoryUsage(); const freeHeap = mem.heapTotal - mem.heapUsed; const ratio = freeHeap / mem.heapTotal; const max = ratio > 0.5 ? 20000 : ratio < 0.2 ? 5000 : 10000; cache.options.maxKeys = max; console.log(`[SCALER] freeHeap ${(freeHeap/1e6).toFixed(1)}MB maxKeys → ${max}`); } setInterval(scaleCache, 60_000);