Node.js based forum software built for the modern web
cache improvements, stats
Barış Soner Uşaklıa73c2628c47a
diff --git a/src/controllers/admin/cache.js b/src/controllers/admin/cache.jsindex a3ce7fba21..4de2045518 100644--- a/src/controllers/admin/cache.js+++ b/src/controllers/admin/cache.js@@ -2,6 +2,8 @@var cacheController = module.exports;+var utils = require('../../utils');+cacheController.get = function (req, res) {var postCache = require('../../posts/cache');var groupCache = require('../../groups').cache;@@ -38,6 +40,9 @@ cacheController.get = function (req, res) {itemCount: objectCache.itemCount,percentFull: ((objectCache.length / objectCache.max) * 100).toFixed(2),dump: req.query.debug ? JSON.stringify(objectCache.dump(), null, 4) : false,+ hits: utils.addCommas(String(objectCache.hits)),+ misses: utils.addCommas(String(objectCache.misses)),+ missRatio: (1 - (objectCache.hits / (objectCache.hits + objectCache.misses))).toFixed(4),};}diff --git a/src/database/mongo/hash.js b/src/database/mongo/hash.jsindex 4985afec2f..becfb83a2f 100644--- a/src/database/mongo/hash.js+++ b/src/database/mongo/hash.js@@ -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);diff --git a/src/views/admin/advanced/cache.tpl b/src/views/admin/advanced/cache.tplindex 1ea4aa39d9..1c2d98ca93 100644--- a/src/views/admin/advanced/cache.tpl+++ b/src/views/admin/advanced/cache.tpl@@ -30,15 +30,20 @@<div class="panel-heading"><i class="fa fa-calendar-o"></i> Object Cache</div><div class="panel-body">++<label>[[admin/advanced/cache:length-to-max]]</label><br/><span>{objectCache.length} / {objectCache.max}</span><br/>-<div class="progress"><div class="progress-bar" role="progressbar" aria-valuenow="{objectCache.percentFull}" aria-valuemin="0" aria-valuemax="100" style="width: {objectCache.percentFull}%;">[[admin/advanced/cache:percent-full, {objectCache.percentFull}]]</div></div>+ <label>Hits:</label> <span>{objectCache.hits}</span><br/>+ <label>Misses:</label> <span>{objectCache.misses}</span><br/>+ <label>Miss Ratio:</label> <span>{objectCache.missRatio}</span><br/>+<!-- IF objectCache.dump --><pre>{objectCache.dump}</pre><!-- ENDIF objectCache.dump -->