This commit is contained in:
sent 2025-05-19 19:10:25 -07:00
parent e059c26083
commit d48831aa9e

15
others/scaler.mjs Normal file
View File

@ -0,0 +1,15 @@
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);