Skip to content

Commit

Permalink
fix(core/cache): update cache key generation to include query limit (D…
Browse files Browse the repository at this point in the history
  • Loading branch information
TonyRL authored Nov 21, 2024
1 parent 7416065 commit d78a47e
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/middleware/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,19 @@ 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)) {
await 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);

Expand Down

0 comments on commit d78a47e

Please sign in to comment.