From 65bc526a91ba8f74dede6b3e0b913dc74d615764 Mon Sep 17 00:00:00 2001 From: sent Date: Thu, 5 Jun 2025 21:24:46 -0700 Subject: [PATCH] Delete others/scaler.mjs --- others/scaler.mjs | 37 ------------------------------------- 1 file changed, 37 deletions(-) delete mode 100644 others/scaler.mjs diff --git a/others/scaler.mjs b/others/scaler.mjs deleted file mode 100644 index 00578b6f..00000000 --- a/others/scaler.mjs +++ /dev/null @@ -1,37 +0,0 @@ -import chokidar from "chokidar"; -import { LRUCache } from "lru-cache"; -import path from "path"; - -let maxKeys = 10_000; -let cache = makeCache(maxKeys); - -function makeCache(maxEntries) { - return new LRUCache({ - maxSize: maxEntries, - ttl: 60_000, - allowStale: false, - updateAgeOnGet: false, - updateAgeOnHas: false - }); -} - -function scaleCache() { - const { heapUsed, heapTotal } = process.memoryUsage(); - const freeHeapRatio = (heapTotal - heapUsed) / heapTotal; - const newMax = freeHeapRatio > 0.5 ? 20_000 : freeHeapRatio < 0.2 ? 5_000 : 10_000; - if (newMax !== maxKeys) { - maxKeys = newMax; - cache = makeCache(maxKeys); - console.log(`[SCALER] freeHeap ${((heapTotal - heapUsed) / 1e6).toFixed(1)}MB → maxKeys: ${maxKeys}`); - } -} - -setInterval(scaleCache, 60_000); -scaleCache(); - -const watchPath = path.join(process.cwd(), "public"); -chokidar.watch(watchPath, { ignoreInitial: true }).on("all", () => { - cache.clear(); -}); - -export { cache }; \ No newline at end of file