diff --git a/src/controllers/admin/cache.js b/src/controllers/admin/cache.js index c8f870559d..51c4fbb51b 100644 --- a/src/controllers/admin/cache.js +++ b/src/controllers/admin/cache.js @@ -23,6 +23,9 @@ cacheController.get = function (req, res) { itemCount: postCache.itemCount, percentFull: percentFull, avgPostSize: avgPostSize, + hits: utils.addCommas(String(postCache.hits)), + misses: utils.addCommas(String(postCache.misses)), + hitRatio: ((postCache.hits / (postCache.hits + postCache.misses) || 0)).toFixed(4), }, groupCache: { length: groupCache.length, diff --git a/src/posts/cache.js b/src/posts/cache.js index 28c58839e8..9c9bbe67d5 100644 --- a/src/posts/cache.js +++ b/src/posts/cache.js @@ -8,5 +8,7 @@ var cache = LRU({ length: function (n) { return n.length; }, maxAge: 0, }); +cache.hits = 0; +cache.misses = 0; module.exports = cache; diff --git a/src/posts/parse.js b/src/posts/parse.js index d6f7165f19..da293d0db8 100644 --- a/src/posts/parse.js +++ b/src/posts/parse.js @@ -27,8 +27,10 @@ module.exports = function (Posts) { if (postData.pid && cache.has(String(postData.pid))) { postData.content = cache.get(String(postData.pid)); + cache.hits += 1; return callback(null, postData); } + cache.misses += 1; async.waterfall([ function (next) { diff --git a/src/views/admin/advanced/cache.tpl b/src/views/admin/advanced/cache.tpl index 302feb07f2..9e7c008ffc 100644 --- a/src/views/admin/advanced/cache.tpl +++ b/src/views/admin/advanced/cache.tpl @@ -19,6 +19,11 @@ [[admin/advanced/cache:percent-full, {postCache.percentFull}]] + + {postCache.hits}
+ {postCache.misses}
+ {postCache.hitRatio}
+