Add refresh for redis cache
This commit is contained in:
parent
313fd8ef76
commit
3dce787c47
|
|
@ -43,7 +43,13 @@ module.exports = function(options = {}) {
|
|||
options.app.context.cache = {
|
||||
get: async (key) => {
|
||||
if (key) {
|
||||
return await redisClient.get(key);
|
||||
const value = await redisClient.get(key);
|
||||
if (value) {
|
||||
let ttl = redisClient.ttl(key);
|
||||
ttl = ttl > expire ? ttl : expire * 2;
|
||||
await redisClient.setex(key, ttl, value);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
},
|
||||
set: async (key, value, maxAge) => {
|
||||
|
|
|
|||
Loading…
Reference in New Issue