2015-12-03 22:00:35 +08:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var _ = require('underscore');
|
|
|
|
|
|
|
|
function CacheStatusController(tableCache) {
|
|
|
|
this.tableCache = tableCache;
|
|
|
|
}
|
|
|
|
|
2015-12-04 01:43:13 +08:00
|
|
|
CacheStatusController.prototype.route = function (app) {
|
2015-12-03 22:00:35 +08:00
|
|
|
app.get(global.settings.base_url + '/cachestatus', this.handleCacheStatus.bind(this));
|
|
|
|
};
|
|
|
|
|
|
|
|
CacheStatusController.prototype.handleCacheStatus = function (req, res) {
|
|
|
|
var tableCacheValues = this.tableCache.values();
|
|
|
|
var totalExplainKeys = tableCacheValues.length;
|
|
|
|
var totalExplainHits = _.reduce(tableCacheValues, function(memo, res) {
|
|
|
|
return memo + res.hits;
|
|
|
|
}, 0);
|
|
|
|
|
|
|
|
res.send({
|
|
|
|
explain: {
|
|
|
|
pid: process.pid,
|
|
|
|
hits: totalExplainHits,
|
|
|
|
keys : totalExplainKeys
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = CacheStatusController;
|