mirror of
https://codeberg.org/PostERG/xamxam.git
synced 2026-05-06 19:19:19 +02:00
feat: system page caching via SystemCache + system_cache SQLite table
Add a TTL-based cache for the expensive checks on the admin system page,
eliminating repeated systemctl subprocess calls (~4×~100ms), curl self-pings
(~200-500ms), disk_*_space() and PHP ini reads on every page load.
Changes:
- storage/migrations/007_system_cache.sql: new migration creating the
system_cache table (key TEXT PK, value TEXT, updated_at INTEGER)
- storage/schema.sql: system_cache table added before pages table
- Applied migration to live storage/posterg.db
- src/SystemCache.php: new class with get/set/isStale/ageSeconds/invalidate;
uses SQLite INSERT … ON CONFLICT upsert; no external dependencies
- src/Database.php: added getDatabasePath(): string accessor
- public/admin/system.php:
- Bootstrap SystemCache at request start using the existing DB PDO handle
- system_status: cached with 2-min TTL (systemctl + curl checks)
- php_info: cached with 1-hour TTL (PHP ini values are runtime-constant)
- disk_info: cached with 5-min TTL (total/free/used/pct tuple)
- Logs section: unchanged — always reads live log tail per active tab
- ?refresh=1 GET param invalidates all three cache keys before rendering
- Status panel heading shows cache badge: '⚡ Cache — il y a Xs' (hit)
or '⟳ Actualisé' (miss/fresh), styled via new .sys-cache-badge rules
- public/assets/css/system.css: .sys-cache-badge / --hit / --miss styles
This commit is contained in:
@@ -254,6 +254,29 @@
|
||||
}
|
||||
.sys-refresh-note a:hover { text-decoration: underline; }
|
||||
|
||||
/* ── Cache freshness badges ──────────────────────────────────────────────── */
|
||||
.sys-cache-badge {
|
||||
display: inline-block;
|
||||
font-size: .68rem;
|
||||
font-weight: 400;
|
||||
font-family: ui-monospace, monospace;
|
||||
padding: .1rem .45rem;
|
||||
border-radius: 3px;
|
||||
margin-left: .7rem;
|
||||
vertical-align: middle;
|
||||
line-height: 1.6;
|
||||
}
|
||||
.sys-cache-badge--hit {
|
||||
background: rgba(255,193,7,.12);
|
||||
color: #ffc107;
|
||||
border: 1px solid rgba(255,193,7,.35);
|
||||
}
|
||||
.sys-cache-badge--miss {
|
||||
background: rgba(76,175,80,.12);
|
||||
color: #4caf50;
|
||||
border: 1px solid rgba(76,175,80,.35);
|
||||
}
|
||||
|
||||
/* ── Nginx config viewer ───────────────────────────────────────────────── */
|
||||
.nginx-source-badge {
|
||||
display: inline-block;
|
||||
|
||||
Reference in New Issue
Block a user