perf(core): replace md5 cache key with xxhash64 (#13974)

* perf(core): replace md5 cache key with xxhash64

* test: add test case for cache TTL key
This commit is contained in:
Tony
2023-12-06 16:58:39 +00:00
committed by GitHub
parent 360fc48d90
commit 3c8ccd948e
5 changed files with 30 additions and 8 deletions

View File

@@ -1,4 +1,4 @@
const md5 = require('@/utils/md5');
const xxhash = require('xxhash-wasm');
const config = require('@/config').value;
const logger = require('@/utils/logger');
const { RequestInProgressError } = require('@/errors');
@@ -81,8 +81,9 @@ module.exports = function (app) {
};
return async (ctx, next) => {
const key = 'koa-redis-cache:' + md5(ctx.request.path);
const controlKey = 'path-requested:' + md5(ctx.request.path);
const { h64ToString } = await xxhash();
const key = 'rsshub:koa-redis-cache:' + h64ToString(ctx.request.path);
const controlKey = 'rsshub:path-requested:' + h64ToString(ctx.request.path);
if (!status.available) {
return next();

View File

@@ -19,10 +19,10 @@ redisClient.on('connect', () => {
});
const getCacheTtlKey = (key) => {
if (key.startsWith('cacheTtl:')) {
throw Error('"cacheTtl:" prefix is reserved for the internal usage, please change your cache key'); // blocking any attempt to get/set the cacheTtl
if (key.startsWith('rsshub:cacheTtl:')) {
throw Error('"rsshub:cacheTtl:" prefix is reserved for the internal usage, please change your cache key'); // blocking any attempt to get/set the cacheTtl
}
return `cacheTtl:${key}`;
return `rsshub:cacheTtl:${key}`;
};
module.exports = {