Skip to content

Commit

Permalink
fix empty cache
Browse files Browse the repository at this point in the history
  • Loading branch information
DIYgod committed Apr 21, 2019
1 parent ec9f9aa commit 697c231
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lib/middleware/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) => {
Expand Down

0 comments on commit 697c231

Please sign in to comment.