efeiefei/mongoose-with-redis

Cache only if data exists in database

rayburks opened this issue · 1 comments

return mongoose.Query.prototype._exec.call(self, function(err, docs) {
if (err) return callback(err);
if(docs != null) {
var str = JSON.stringify(docs);
redisClient.setex(key, cacheOptions.expires, str);
}
return callback(null, docs);
});

If a database call returns null, the value null will be cached. I would expect not to cache a null value.
The callback return null, thats fine.
What do you think?

Regards Ray

@rayburks
Maybe this depends on the business.
But, from the perspective of the cache system, if not cache null, the back end pressure will increase.
I think that null can be considered as ordinary data, relying on redis expire time to update, just like the other data.