fix(core): unnecessary redis io (#9875)

This commit is contained in:
Tony
2022-06-02 21:33:24 +08:00
committed by GitHub
parent 67b3602574
commit 548395b4b4
+7 -2
View File
@@ -32,8 +32,10 @@ module.exports = {
let [value, cacheTtl] = await redisClient.mget(key, cacheTtlKey);
if (value && refresh) {
if (!cacheTtl) {
// if cacheTtl is not set, that means the cache expire time is contentExpire
cacheTtl = config.cache.contentExpire;
redisClient.set(cacheTtlKey, cacheTtl, 'EX', cacheTtl);
// dont save cacheTtl to Redis, as it is the default value
// redisClient.set(cacheTtlKey, cacheTtl, 'EX', cacheTtl);
} else {
redisClient.expire(cacheTtlKey, cacheTtl);
}
@@ -54,7 +56,10 @@ module.exports = {
value = JSON.stringify(value);
}
if (key) {
redisClient.set(getCacheTtlKey(key), maxAge, 'EX', maxAge);
if (maxAge !== config.cache.contentExpire) {
// Only set cacheTtlKey if maxAge !== contentExpire
redisClient.set(getCacheTtlKey(key), maxAge, 'EX', maxAge);
}
return redisClient.set(key, value, 'EX', maxAge); // setMode: https://redis.io/commands/set
}
},