Files
NodeBB/src/controllers/admin/cache.js

63 lines
1.6 KiB
JavaScript
Raw Normal View History

'use strict';
2019-08-13 10:36:48 -04:00
const cacheController = module.exports;
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;
2021-02-06 14:10:15 -07:00
const { objectCache } = require('../../database');
2019-08-13 10:36:48 -04:00
const localCache = require('../../cache');
function getInfo(cache) {
return {
length: cache.length,
max: cache.max,
Update to lru-cache@^7 (#10815) * chore(deps): bump lru-cache from 6.0.0 to 7.13.1 in /install Bumps [lru-cache](https://github.com/isaacs/node-lru-cache) from 6.0.0 to 7.13.1. - [Release notes](https://github.com/isaacs/node-lru-cache/releases) - [Changelog](https://github.com/isaacs/node-lru-cache/blob/main/CHANGELOG.md) - [Commits](https://github.com/isaacs/node-lru-cache/compare/v6.0.0...v7.13.1) --- updated-dependencies: - dependency-name: lru-cache dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> * fix(lru-cache): remove unneeded `length` params for cache creation, as `maxSize` was not used in those init calls, also renamed some methods to match new method names in lru-cache [breaking] Added deprecation notices for old params * fix: replace three direct calls to lru-cache with call to cacheCreate, moved cache creation call in uploads to run on first init as config is not populated at lib init * test: move configs init above cache reset calls in databasemock * move some more code above cache clear * refactor: remove unused * test: lru * test: more debug * test: on more test * use await helpers.uploadFile * fix: tests remove logs * fix: acp cache page * fix: add in one more guard again cache instantiation with `length` prop but no `maxSize` prop * fix(deps): bump markdown Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Barış Soner Uşaklı <barisusakli@gmail.com>
2022-08-10 13:24:16 -04:00
maxSize: cache.maxSize,
itemCount: cache.itemCount,
Update to lru-cache@^7 (#10815) * chore(deps): bump lru-cache from 6.0.0 to 7.13.1 in /install Bumps [lru-cache](https://github.com/isaacs/node-lru-cache) from 6.0.0 to 7.13.1. - [Release notes](https://github.com/isaacs/node-lru-cache/releases) - [Changelog](https://github.com/isaacs/node-lru-cache/blob/main/CHANGELOG.md) - [Commits](https://github.com/isaacs/node-lru-cache/compare/v6.0.0...v7.13.1) --- updated-dependencies: - dependency-name: lru-cache dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> * fix(lru-cache): remove unneeded `length` params for cache creation, as `maxSize` was not used in those init calls, also renamed some methods to match new method names in lru-cache [breaking] Added deprecation notices for old params * fix: replace three direct calls to lru-cache with call to cacheCreate, moved cache creation call in uploads to run on first init as config is not populated at lib init * test: move configs init above cache reset calls in databasemock * move some more code above cache clear * refactor: remove unused * test: lru * test: more debug * test: on more test * use await helpers.uploadFile * fix: tests remove logs * fix: acp cache page * fix: add in one more guard again cache instantiation with `length` prop but no `maxSize` prop * fix(deps): bump markdown Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Barış Soner Uşaklı <barisusakli@gmail.com>
2022-08-10 13:24:16 -04:00
percentFull: cache.name === 'post' ?
((cache.length / cache.maxSize) * 100).toFixed(2) :
((cache.itemCount / 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,
};
}
2019-08-13 10:36:48 -04:00
const data = {
postCache: getInfo(postCache),
groupCache: getInfo(groupCache),
localCache: getInfo(localCache),
};
if (objectCache) {
data.objectCache = getInfo(objectCache);
}
res.render('admin/advanced/cache', data);
};
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);
2021-02-03 23:59:08 -07:00
res.setHeader('Content-disposition', `attachment; filename= ${req.query.name}-cache.json`);
res.setHeader('Content-type', 'application/json');
2021-02-04 00:01:39 -07:00
res.write(data, (err) => {
if (err) {
return next(err);
}
res.end();
});
};