Add refresh for redis cache

This commit is contained in:
Henry 2019-01-24 22:50:32 +00:00
parent 313fd8ef76
commit 3dce787c47
1 changed files with 7 additions and 1 deletions

View File

@ -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) => {