refactor: cache page to table

display notif cache too
This commit is contained in:
Barış Soner Uşaklı
2026-02-11 20:17:06 -05:00
parent 756e2434ad
commit 7336c58cdf
5 changed files with 71 additions and 69 deletions

View File

@@ -4,6 +4,7 @@
"group-cache": "Group Cache",
"local-cache": "Local Cache",
"object-cache": "Object Cache",
"notification-cache": "Notification Cache",
"percent-full": "%1% Full",
"post-cache-size": "Post Cache Size",
"items-in-cache": "Items in Cache"

View File

@@ -10,6 +10,7 @@ cacheController.get = async function (req, res) {
const groupCache = require('../../groups').cache;
const { objectCache } = require('../../database');
const localCache = require('../../cache');
const { delayCache } = require('../../notifications');
const uptimeInSeconds = process.uptime();
function getInfo(cache) {
return {
@@ -32,6 +33,7 @@ cacheController.get = async function (req, res) {
post: postCache,
group: groupCache,
local: localCache,
notification: delayCache,
};
if (objectCache) {
caches.object = objectCache;

View File

@@ -30,6 +30,8 @@ const notificationCache = ttlCache({
dispose: sendEmail,
});
Notifications.delayCache = notificationCache;
Notifications.baseTypes = [
'notificationType_upvote',
'notificationType_new-topic',

View File

@@ -6,13 +6,7 @@ const db = require('../../database');
const plugins = require('../../plugins');
SocketCache.clear = async function (socket, data) {
let caches = {
post: require('../../posts/cache').getOrCreate(),
object: db.objectCache,
group: require('../../groups').cache,
local: require('../../cache'),
};
caches = await plugins.hooks.fire('filter:admin.cache.get', caches);
const caches = await getAvailableCaches();
if (!caches[data.name]) {
return;
}
@@ -20,15 +14,20 @@ SocketCache.clear = async function (socket, data) {
};
SocketCache.toggle = async function (socket, data) {
let caches = {
post: require('../../posts/cache').getOrCreate(),
object: db.objectCache,
group: require('../../groups').cache,
local: require('../../cache'),
};
caches = await plugins.hooks.fire('filter:admin.cache.get', caches);
const caches = await getAvailableCaches();
if (!caches[data.name]) {
return;
}
caches[data.name].enabled = data.enabled;
};
async function getAvailableCaches() {
const caches = {
post: require('../../posts/cache').getOrCreate(),
object: db.objectCache,
group: require('../../groups').cache,
local: require('../../cache'),
notification: require('../../notifications').delayCache,
};
return await plugins.hooks.fire('filter:admin.cache.get', caches);
}

View File

@@ -9,66 +9,64 @@
</div>
</div>
<div class="row px-2">
{{{ each caches }}}
<div class="col-xl-3">
<div class="card">
<div class="card-header">
<div class="d-flex gap-2 justify-content-between align-items-center">
<div class="d-flex gap-1 align-items-center">
<div class="form-check form-switch text-sm" data-name="{@key}" style="min-height: initial;">
<input class="form-check-input" type="checkbox" {{{if caches.enabled}}}checked{{{end}}}>
<div>
<div class="table-responsive">
<table class="table table-sm text-sm">
<thead>
<tr>
<td></td>
<td class="text-end">capacity</td>
<td class="text-end">count</td>
<td class="text-end">size</td>
<td class="text-end">hits</td>
<td class="text-end">misses</td>
<td class="text-end">hit ratio</td>
<td class="text-end">hits/sec</td>
<td class="text-end">ttl</td>
<td></td>
</tr>
</thead>
<tbody class="text-xs">
{{{ each caches }}}
<tr class="align-middle">
<td>
<div class="d-flex gap-1 align-items-center">
<div class="form-check form-switch text-sm" data-name="{@key}" style="min-height: initial;">
<input class="form-check-input" type="checkbox" {{{if caches.enabled}}}checked{{{end}}}>
</div>
[[admin/advanced/cache:{@key}-cache]]
</div>
[[admin/advanced/cache:{@key}-cache]]
</div>
<div class="d-flex gap-1">
<a href="{config.relative_path}/api/admin/advanced/cache/dump?name={@key}" class="btn btn-light btn-sm"><i class="fa fa-download"></i></a>
<a class="btn btn-sm btn-danger clear" data-name="{@key}"><i class="fa fa-trash"></i></a>
</div>
</div>
</div>
<div class="card-body">
<div class="progress mb-3" style="height:20px;">
<div class="progress-bar" role="progressbar" aria-valuenow="{./percentFull}" aria-valuemin="0" aria-valuemax="100" style="width: {./percentFull}%;">
[[admin/advanced/cache:percent-full, {./percentFull}]]
</div>
</div>
</td>
<td class="text-end">{./percentFull}%</td>
<td class="text-end">{{{if ./length}}}{./length}{{{else}}}{./itemCount}{{{end}}} </td>
<td class="text-end">
{{{ if (@key == "post") }}}
<div class="d-flex justify-content-end align-items-center gap-1">
<a href="#" data-bs-toggle="tooltip" data-bs-title="Changing the post cache size requires a restart."><i class="fa-regular fa-circle-question"></i></a>
<div class="mb-2">
<label>Size:</label> <span class="fw-bold">{{{if ./length}}}{./length}{{{else}}}{./itemCount}{{{end}}} / {{{if ./max}}}{./max}{{{else}}}{./maxSize}{{{end}}}</span>
</div>
<input id="postCacheSize" style="width:100px;" type="text" class="text-end form-control form-control-sm" value="" data-field="postCacheSize">
<div class="mb-2">
<label>Hits:</label> <span class="fw-bold">{./hits}</span>
</div>
<div class="mb-2">
<label>Misses:</label> <span class="fw-bold">{./misses}</span>
</div>
<div class="mb-2">
<label>Hit Ratio:</label> <span class="fw-bold">{./hitRatio}</span>
</div>
<div class="mb-2">
<label>Hits / Sec:</label> <span class="fw-bold">{./hitsPerSecond}</span>
</div>
{{{ if ./ttl }}}
<div class="mb-2">
<label>TTL:</label> <span class="fw-bold">{./ttl}</span>
</div>
</div>
{{{ else }}}
{{{if ./max}}}{./max}{{{else}}}{./maxSize}{{{end}}}
{{{ end }}}
</td>
<td class="text-end">{./hits}</td>
<td class="text-end">{./misses}</td>
<td class="text-end">{./hitRatio}</td>
<td class="text-end">{./hitsPerSecond}</td>
<td class="text-end">{./ttl}</td>
<td class="">
<div class="d-flex justify-content-end gap-1">
<a href="{config.relative_path}/api/admin/advanced/cache/dump?name={@key}" class="btn btn-light btn-sm"><i class="fa fa-download"></i></a>
<a class="btn btn-sm btn-danger clear" data-name="{@key}"><i class="fa fa-trash"></i></a>
</div>
</td>
</tr>
{{{ end }}}
{{{ if (@key == "post") }}}
<hr/>
<div class="mb-3">
<label for="postCacheSize">[[admin/advanced/cache:post-cache-size]]</label>
<input id="postCacheSize" type="text" class="form-control" value="" data-field="postCacheSize">
</div>
{{{ end }}}
</div>
</tbody>
</table>
</div>
</div>
{{{ end }}}
</div>
</div>