fix empty cache

This commit is contained in:
DIYgod 2019-04-21 20:36:09 +08:00
parent ec9f9aa018
commit 697c231f4e
No known key found for this signature in database
GPG Key ID: EC0B76A252D3EF67
1 changed files with 8 additions and 3 deletions

View File

@ -36,11 +36,12 @@ module.exports = function(app, options = {}) {
app.context.cache = {
get: async (key) => {
if (key) {
const value = await redisClient.get(key);
let value = await redisClient.get(key);
if (value) {
await redisClient.expire(key, 24 * 60 * 60);
value = value + '';
}
return value + '';
return value;
}
},
set: async function(key, value, maxAge = 24 * 60 * 60) {
@ -81,7 +82,11 @@ module.exports = function(app, options = {}) {
app.context.cache = {
get: (key) => {
if (key) {
return routeCache.get(key) + '';
let value = routeCache.get(key);
if (value) {
value = value + '';
}
return value;
}
},
set: (key, value, maxAge = 24 * 60 * 60) => {