mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-19 06:38:55 +08:00
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:
7
lib/middleware/cache/index.js
vendored
7
lib/middleware/cache/index.js
vendored
@@ -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();
|
||||
|
||||
6
lib/middleware/cache/redis.js
vendored
6
lib/middleware/cache/redis.js
vendored
@@ -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 = {
|
||||
|
||||
Reference in New Issue
Block a user