← back to Wallco Ai
/admin/health: surface random-ETag hit/miss/rate alongside by-color cache stats
f12547c839a4efd74bbdd886ea0571c464c1a7aa · 2026-05-13 07:28:05 -0700 · SteveStudio2
Files touched
Diff
commit f12547c839a4efd74bbdd886ea0571c464c1a7aa
Author: SteveStudio2 <steve@designerwallcoverings.com>
Date: Wed May 13 07:28:05 2026 -0700
/admin/health: surface random-ETag hit/miss/rate alongside by-color cache stats
---
server.js | 15 ++++++++++++++-
1 file changed, 14 insertions(+), 1 deletion(-)
diff --git a/server.js b/server.js
index 8b0e66f..dbba39b 100644
--- a/server.js
+++ b/server.js
@@ -395,6 +395,9 @@ const _BY_COLOR_MAX = 1000;
const _byColorCache = new Map(); // key -> { body, expiresAt }
let _byColorCacheVer = 0; // bump to invalidate
const _byColorStats = { hits: 0, misses: 0, evictions: 0, since: Date.now() };
+// /api/designs/random ETag stats — only seeded calls participate (unseeded is no-store).
+// "hits" = 304 returned (client revalidated), "misses" = full 200 with body.
+const _randomStats = { hits: 0, misses: 0, since: Date.now() };
app.get('/api/designs/by-color', (req, res) => {
const hex = String(req.query.hex || '').trim();
const n = Math.max(1, Math.min(50, parseInt(req.query.n || '12', 10)));
@@ -504,7 +507,8 @@ app.get('/api/designs/random', (req, res) => {
res.setHeader('ETag', etag);
res.setHeader('Cache-Control', 'private, max-age=0, must-revalidate');
const inm = req.headers['if-none-match'];
- if (inm && inm === etag) return res.status(304).end();
+ if (inm && inm === etag) { _randomStats.hits++; return res.status(304).end(); }
+ _randomStats.misses++;
} else {
res.setHeader('Cache-Control', 'no-store');
}
@@ -10494,6 +10498,15 @@ app.get('/admin/health', (req, res) => {
hit_rate: total > 0 ? Math.round((_byColorStats.hits / total) * 1000) / 10 : null,
since: new Date(_byColorStats.since).toISOString(),
},
+ random_etag: (() => {
+ const t = _randomStats.hits + _randomStats.misses;
+ return {
+ hits: _randomStats.hits,
+ misses: _randomStats.misses,
+ hit_rate: t > 0 ? Math.round((_randomStats.hits / t) * 1000) / 10 : null,
+ since: new Date(_randomStats.since).toISOString(),
+ };
+ })(),
});
});
← 0ec07a8 drunk-animals: end-to-end smoke test, 19/19 passing
·
back to Wallco Ai
·
drunk-animals: daemon preflight self-heals id_seq desync 5312be8 →