From 94421af2dd5aedd019601b03640b102a6729c524 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=CA=9C=C9=AA=C9=B4=E1=B4=87=C9=AA=20N=E1=B4=8F=E1=B4=9C?= =?UTF-8?q?=E1=B4=A2=E1=B4=87=C9=B4?= <157171073+Shineii86@users.noreply.github.com> Date: Thu, 25 Jun 2026 10:03:22 +0530 Subject: [PATCH] Add no-cache headers to /random to prevent CDN caching --- src/routes/apiRoutes.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/routes/apiRoutes.js b/src/routes/apiRoutes.js index 325a3a3..9667f63 100644 --- a/src/routes/apiRoutes.js +++ b/src/routes/apiRoutes.js @@ -320,11 +320,10 @@ const createApiRoutes = (jsonResponse, jsonError, startTime) => { // ---- FEATURE: Random anime of the day ---- router.get("/random", async (req, res) => { try { - // NOTE: Use multiple entropy sources for randomness in serverless - const now = Date.now(); - const hrtime = process.hrtime(); - const entropy = (now * 31 + hrtime[0] * 17 + hrtime[1] * 13) ^ (process.pid * 7); - const randomPage = (Math.abs(entropy) % 499) + 1; + // NOTE: Disable CDN cache + use request timestamp for true randomness + res.setHeader("Cache-Control", "no-store, no-cache, must-revalidate"); + res.setHeader("Pragma", "no-cache"); + const randomPage = (Date.now() % 499) + 1; const data = await anilist.getCollection("POPULARITY_DESC", null, randomPage, 1); const anime = data.results[0];