2016-09-14 21:00:41 +03:00
|
|
|
'use strict';
|
|
|
|
|
|
2019-08-13 10:36:48 -04:00
|
|
|
const cacheController = module.exports;
|
2016-09-14 21:00:41 +03:00
|
|
|
|
2019-08-13 10:36:48 -04:00
|
|
|
const utils = require('../../utils');
|
2017-10-25 18:20:44 -04:00
|
|
|
|
2017-02-18 15:05:36 -07:00
|
|
|
cacheController.get = function (req, res) {
|
2019-08-13 10:36:48 -04:00
|
|
|
const postCache = require('../../posts/cache');
|
|
|
|
|
const groupCache = require('../../groups').cache;
|
|
|
|
|
const objectCache = require('../../database').objectCache;
|
|
|
|
|
const localCache = require('../../cache');
|
2020-11-07 22:06:25 -05:00
|
|
|
|
|
|
|
|
function getInfo(cache) {
|
|
|
|
|
return {
|
|
|
|
|
length: cache.length,
|
|
|
|
|
max: cache.max,
|
|
|
|
|
itemCount: cache.itemCount,
|
|
|
|
|
percentFull: ((cache.length / cache.max) * 100).toFixed(2),
|
|
|
|
|
hits: utils.addCommas(String(cache.hits)),
|
|
|
|
|
misses: utils.addCommas(String(cache.misses)),
|
|
|
|
|
hitRatio: ((cache.hits / (cache.hits + cache.misses) || 0)).toFixed(4),
|
|
|
|
|
enabled: cache.enabled,
|
|
|
|
|
};
|
2016-09-14 21:00:41 +03:00
|
|
|
}
|
|
|
|
|
|
2019-08-13 10:36:48 -04:00
|
|
|
const data = {
|
2020-11-07 22:06:25 -05:00
|
|
|
postCache: getInfo(postCache),
|
|
|
|
|
groupCache: getInfo(groupCache),
|
|
|
|
|
localCache: getInfo(localCache),
|
2017-10-23 18:31:16 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (objectCache) {
|
2020-11-07 22:06:25 -05:00
|
|
|
data.objectCache = getInfo(objectCache);
|
2017-10-23 18:31:16 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
res.render('admin/advanced/cache', data);
|
2016-09-14 21:00:41 +03:00
|
|
|
};
|
2020-11-06 23:13:12 -05:00
|
|
|
|
|
|
|
|
cacheController.dump = function (req, res, next) {
|
|
|
|
|
const caches = {
|
|
|
|
|
post: require('../../posts/cache'),
|
|
|
|
|
object: require('../../database').objectCache,
|
|
|
|
|
group: require('../../groups').cache,
|
|
|
|
|
local: require('../../cache'),
|
|
|
|
|
};
|
|
|
|
|
if (!caches[req.query.name]) {
|
|
|
|
|
return next();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const data = JSON.stringify(caches[req.query.name].dump(), null, 4);
|
|
|
|
|
res.setHeader('Content-disposition', 'attachment; filename= ' + req.query.name + '-cache.json');
|
|
|
|
|
res.setHeader('Content-type', 'application/json');
|
|
|
|
|
res.write(data, function (err) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return next(err);
|
|
|
|
|
}
|
|
|
|
|
res.end();
|
|
|
|
|
});
|
|
|
|
|
};
|