mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-16 02:36:16 +01:00
cache improvements, stats
This commit is contained in:
@@ -13,6 +13,8 @@ module.exports = function (db, module) {
|
||||
maxAge: 0,
|
||||
});
|
||||
|
||||
cache.misses = 0;
|
||||
cache.hits = 0;
|
||||
module.objectCache = cache;
|
||||
|
||||
pubsub.on('mongo:hash:cache:del', function (key) {
|
||||
@@ -86,9 +88,14 @@ module.exports = function (db, module) {
|
||||
}
|
||||
|
||||
var nonCachedKeys = keys.filter(function (key) {
|
||||
return !cache.get(key);
|
||||
return cache.get(key) === undefined;
|
||||
});
|
||||
|
||||
var hits = keys.length - nonCachedKeys.length;
|
||||
var misses = keys.length - hits;
|
||||
cache.hits += hits;
|
||||
cache.misses += misses;
|
||||
|
||||
if (!nonCachedKeys.length) {
|
||||
return getFromCache(callback);
|
||||
}
|
||||
@@ -98,12 +105,9 @@ module.exports = function (db, module) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
data.forEach(function (objectData) {
|
||||
if (objectData) {
|
||||
var key = objectData._key;
|
||||
delete objectData._key;
|
||||
cache.set(key, objectData);
|
||||
}
|
||||
var map = helpers.toMap(data);
|
||||
nonCachedKeys.forEach(function (key) {
|
||||
cache.set(key, map[key] || null);
|
||||
});
|
||||
|
||||
getFromCache(callback);
|
||||
|
||||
Reference in New Issue
Block a user