From 88454260012333fc2a058d5585dae00cf2052448 Mon Sep 17 00:00:00 2001 From: sent Date: Thu, 5 Jun 2025 21:10:10 -0700 Subject: [PATCH 1/9] 60000 --- index.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.mjs b/index.mjs index 8dce7130..6a4f97a5 100644 --- a/index.mjs +++ b/index.mjs @@ -57,7 +57,7 @@ import "./others/warmup.mjs"; const cache = new LRUCache({ maxSize: 1000, - ttl: 345600000, + ttl: 60000, allowStale: false, sizeCalculation: (value, key) => Buffer.byteLength(value) + Buffer.byteLength(key) }); From c13a7085841f87b2fee154c91d173304588737a5 Mon Sep 17 00:00:00 2001 From: sent Date: Thu, 5 Jun 2025 21:12:21 -0700 Subject: [PATCH 2/9] Update others/scaler.mjs --- others/scaler.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/others/scaler.mjs b/others/scaler.mjs index 15ac37c9..36f867d7 100644 --- a/others/scaler.mjs +++ b/others/scaler.mjs @@ -6,7 +6,7 @@ let cache = makeCache(maxKeys); function makeCache(maxEntries) { return new LRUCache({ maxSize: maxEntries, - ttl: 4 * 24 * 60 * 60 * 1_000, + ttl: 60_000, allowStale: false, updateAgeOnGet: false, updateAgeOnHas: false, From ff50de3064c70544c329b046594ef282719b9291 Mon Sep 17 00:00:00 2001 From: sent Date: Thu, 5 Jun 2025 21:12:54 -0700 Subject: [PATCH 3/9] Update index.mjs --- index.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.mjs b/index.mjs index 6a4f97a5..64b578b5 100644 --- a/index.mjs +++ b/index.mjs @@ -57,7 +57,7 @@ import "./others/warmup.mjs"; const cache = new LRUCache({ maxSize: 1000, - ttl: 60000, + ttl: 60_000, allowStale: false, sizeCalculation: (value, key) => Buffer.byteLength(value) + Buffer.byteLength(key) }); From b622f3cb9b7a3f7706db0fb4902927c1e46e3d97 Mon Sep 17 00:00:00 2001 From: sent Date: Thu, 5 Jun 2025 21:18:57 -0700 Subject: [PATCH 4/9] Cool Thingy --- others/scaler.mjs | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/others/scaler.mjs b/others/scaler.mjs index 36f867d7..9a2b936e 100644 --- a/others/scaler.mjs +++ b/others/scaler.mjs @@ -1,36 +1,37 @@ -import { LRUCache } from 'lru-cache'; +import fs from "fs"; +import path from "path"; +import { LRUCache } from "lru-cache"; let maxKeys = 10_000; -let cache = makeCache(maxKeys); +let cache = makeCache(maxKeys); function makeCache(maxEntries) { return new LRUCache({ maxSize: maxEntries, - ttl: 60_000, - allowStale: false, + ttl: 60_000, + allowStale: false, updateAgeOnGet: false, - updateAgeOnHas: 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; - + 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}`); + console.log(`[SCALER] freeHeap ${((heapTotal - heapUsed) / 1e6).toFixed(1)}MB → maxKeys: ${maxKeys}`); } } setInterval(scaleCache, 60_000); scaleCache(); -export { cache }; \ No newline at end of file +const watchPath = path.join(process.cwd(), "public"); +fs.watch(watchPath, { recursive: true }, () => { + cache.clear(); +}); + +export { cache }; From a08375832542eb46614e41348a8f8df74d86255a Mon Sep 17 00:00:00 2001 From: sent Date: Thu, 5 Jun 2025 21:22:22 -0700 Subject: [PATCH 5/9] 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 9a2b936e..00000000 --- a/others/scaler.mjs +++ /dev/null @@ -1,37 +0,0 @@ -import fs from "fs"; -import path from "path"; -import { LRUCache } from "lru-cache"; - -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"); -fs.watch(watchPath, { recursive: true }, () => { - cache.clear(); -}); - -export { cache }; From bc878dfb6412ce84ed8f80dce4b307b5e80457e1 Mon Sep 17 00:00:00 2001 From: sent Date: Thu, 5 Jun 2025 21:23:14 -0700 Subject: [PATCH 6/9] Add others/scaler.mjs --- others/scaler.mjs | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 others/scaler.mjs diff --git a/others/scaler.mjs b/others/scaler.mjs new file mode 100644 index 00000000..00578b6f --- /dev/null +++ b/others/scaler.mjs @@ -0,0 +1,37 @@ +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 From 65bc526a91ba8f74dede6b3e0b913dc74d615764 Mon Sep 17 00:00:00 2001 From: sent Date: Thu, 5 Jun 2025 21:24:46 -0700 Subject: [PATCH 7/9] 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 From 78fbc42a0c321a709b2b6e6aa54966a49a023093 Mon Sep 17 00:00:00 2001 From: sent Date: Thu, 5 Jun 2025 21:25:37 -0700 Subject: [PATCH 8/9] Add others/scaler.mjs --- others/scaler.mjs | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 others/scaler.mjs diff --git a/others/scaler.mjs b/others/scaler.mjs new file mode 100644 index 00000000..7b31e40f --- /dev/null +++ b/others/scaler.mjs @@ -0,0 +1,36 @@ +What about this import { LRUCache } from 'lru-cache'; + +let maxKeys = 10_000; +let cache = makeCache(maxKeys); + +function makeCache(maxEntries) { + return new LRUCache({ + maxSize: maxEntries, + ttl: 4 * 24 * 60 * 60 * 1_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(); + +export { cache }; \ No newline at end of file From 2b1a9124782c905ae118ba17f3383da0e8bc735b Mon Sep 17 00:00:00 2001 From: sent Date: Thu, 5 Jun 2025 21:26:40 -0700 Subject: [PATCH 9/9] Update others/scaler.mjs --- others/scaler.mjs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/others/scaler.mjs b/others/scaler.mjs index 7b31e40f..32c69bf1 100644 --- a/others/scaler.mjs +++ b/others/scaler.mjs @@ -1,4 +1,4 @@ -What about this import { LRUCache } from 'lru-cache'; +import { LRUCache } from 'lru-cache'; let maxKeys = 10_000; let cache = makeCache(maxKeys); @@ -6,7 +6,7 @@ let cache = makeCache(maxKeys); function makeCache(maxEntries) { return new LRUCache({ maxSize: maxEntries, - ttl: 4 * 24 * 60 * 60 * 1_000, + ttl: 60_000, allowStale: false, updateAgeOnGet: false, updateAgeOnHas: false,