add cache hits/misses to posts cache

v1.18.x
Barış Soner Uşaklı 6 years ago
parent b57db7fd8e
commit 6c15aee888

@ -23,6 +23,9 @@ cacheController.get = function (req, res) {
itemCount: postCache.itemCount, itemCount: postCache.itemCount,
percentFull: percentFull, percentFull: percentFull,
avgPostSize: avgPostSize, 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: { groupCache: {
length: groupCache.length, length: groupCache.length,

@ -8,5 +8,7 @@ var cache = LRU({
length: function (n) { return n.length; }, length: function (n) { return n.length; },
maxAge: 0, maxAge: 0,
}); });
cache.hits = 0;
cache.misses = 0;
module.exports = cache; module.exports = cache;

@ -27,8 +27,10 @@ module.exports = function (Posts) {
if (postData.pid && cache.has(String(postData.pid))) { if (postData.pid && cache.has(String(postData.pid))) {
postData.content = cache.get(String(postData.pid)); postData.content = cache.get(String(postData.pid));
cache.hits += 1;
return callback(null, postData); return callback(null, postData);
} }
cache.misses += 1;
async.waterfall([ async.waterfall([
function (next) { function (next) {

@ -19,6 +19,11 @@
[[admin/advanced/cache:percent-full, {postCache.percentFull}]] [[admin/advanced/cache:percent-full, {postCache.percentFull}]]
</div> </div>
</div> </div>
<label>Hits:</label> <span>{postCache.hits}</span><br/>
<label>Misses:</label> <span>{postCache.misses}</span><br/>
<label>Hit Ratio:</label> <span>{postCache.hitRatio}</span><br/>
<div class="form-group"> <div class="form-group">
<label for="postCacheSize">[[admin/advanced/cache:post-cache-size]]</label> <label for="postCacheSize">[[admin/advanced/cache:post-cache-size]]</label>
<input id="postCacheSize" type="text" class="form-control" value="" data-field="postCacheSize"> <input id="postCacheSize" type="text" class="form-control" value="" data-field="postCacheSize">

Loading…
Cancel
Save