From d78a47ec7bb3dc512c2776a00919b69467ee8ad4 Mon Sep 17 00:00:00 2001 From: Tony Date: Thu, 21 Nov 2024 09:41:11 -0800 Subject: [PATCH] fix(core/cache): update cache key generation to include query limit (#17674) --- lib/middleware/cache.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/middleware/cache.ts b/lib/middleware/cache.ts index 6c5596f5af..d31a26a5b0 100644 --- a/lib/middleware/cache.ts +++ b/lib/middleware/cache.ts @@ -8,7 +8,7 @@ import { Data } from '@/types'; const bypassList = new Set(['/', '/robots.txt', '/logo.png', '/favicon.ico']); // only give cache string, as the `!` condition tricky -// md5 is used to shrink key size +// XXH64 is used to shrink key size // plz, write these tips in comments! const middleware: MiddlewareHandler = async (ctx, next) => { if (!cacheModule.status.available || bypassList.has(ctx.req.path)) { @@ -16,9 +16,11 @@ const middleware: MiddlewareHandler = async (ctx, next) => { return; } + const requestPath = ctx.req.path; + const limit = ctx.req.query('limit') ? `:${ctx.req.query('limit')}` : ''; const { h64ToString } = await xxhash(); - const key = 'rsshub:koa-redis-cache:' + h64ToString(ctx.req.path); - const controlKey = 'rsshub:path-requested:' + h64ToString(ctx.req.path); + const key = 'rsshub:koa-redis-cache:' + h64ToString(requestPath + limit); + const controlKey = 'rsshub:path-requested:' + h64ToString(requestPath + limit); const isRequesting = await cacheModule.globalCache.get(controlKey);