Skip to content

Commit

Permalink
feat: ability to clear cache from acp
Browse files Browse the repository at this point in the history
  • Loading branch information
barisusakli committed Jul 29, 2020
1 parent 69fb152 commit bbc7737
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 8 deletions.
20 changes: 20 additions & 0 deletions public/src/admin/advanced/cache.js
@@ -0,0 +1,20 @@
'use strict';

define('admin/advanced/cache', function () {
var Cache = {};
Cache.init = function () {
require(['admin/settings'], function (Settings) {
Settings.prepare();
});

$('#clear').on('click', function () {
socket.emit('admin.cache.clear', function (err) {
if (err) {
return app.alertError(err.message);
}
ajaxify.refresh();
});
});
};
return Cache;
});
2 changes: 1 addition & 1 deletion src/controllers/admin/cache.js
Expand Up @@ -45,7 +45,7 @@ cacheController.get = function (req, res) {
dump: req.query.debug ? JSON.stringify(localCache.dump(), null, 4) : false,
hits: utils.addCommas(String(localCache.hits)),
misses: utils.addCommas(String(localCache.misses)),
hitRatio: (localCache.hits / (localCache.hits + localCache.misses)).toFixed(4),
hitRatio: ((localCache.hits / (localCache.hits + localCache.misses) || 0)).toFixed(4),
},
};

Expand Down
1 change: 1 addition & 0 deletions src/socket.io/admin.js
Expand Up @@ -32,6 +32,7 @@ SocketAdmin.logs = require('./admin/logs');
SocketAdmin.errors = require('./admin/errors');
SocketAdmin.uploads = require('./admin/uploads');
SocketAdmin.digest = require('./admin/digest');
SocketAdmin.cache = require('./admin/cache');

SocketAdmin.before = async function (socket, method) {
const isAdmin = await user.isAdministrator(socket.uid);
Expand Down
10 changes: 10 additions & 0 deletions src/socket.io/admin/cache.js
@@ -0,0 +1,10 @@
'use strict';

const SocketCache = module.exports;

SocketCache.clear = async function () {
require('../../posts/cache').reset();
require('../../database').objectCache.reset();
require('../../groups').cache.reset();
require('../../cache').reset();
};
9 changes: 2 additions & 7 deletions src/views/admin/advanced/cache.tpl
Expand Up @@ -106,14 +106,9 @@
<div class="panel panel-default">
<div class="panel-heading">[[admin/advanced/cache:control-panel]]</div>
<div class="panel-body">
<button class="btn btn-primary" id="save">[[admin/advanced/cache:update-settings]]</button>
<button class="btn btn-primary btn-block" id="save">[[admin/advanced/cache:update-settings]]</button>
<button class="btn btn-info btn-block" id="clear">[[admin/advanced/cache:clear]]</button>
</div>
</div>
</div>
</div>

<script>
require(['admin/settings'], function(Settings) {
Settings.prepare();
});
</script>

0 comments on commit bbc7737

Please sign in to comment.