feat(cache): server-side LRU primitive + per-user invalidation helpers

Extends the v1.4.33 Coach snapshot LRU shape into a reusable
ServerCache<T> with TTL expiry, capacity-bounded LRU eviction,
single-flight read coalescing, prefix delete, and per-instance
hit/miss/eviction/stampede counters. Adds five invalidation helpers
keyed by the per-user prefix scheme so write endpoints can flush every
cache that may reflect their changed rows in a single call.

The cached() wrapper attaches cache.<name>.outcome + cache.<name>.key_hash
to the active wide event so production logs carry the hit ratio without
leaking the userId portion of the cache key.

Hand-rolled to keep the dependency surface at zero — same recipe as the
snapshot cache the dashboard already relies on. Process-local; multi-
instance staleness is bounded by TTL, the Redis migration path stays a
future option.
This commit is contained in:
Marc-André Bombeck committed 2026-05-16 20:55:05 +02:00
1 parent fef24a89bb
commit a5dd8e1d1a
7 files changed
+755

No files matched your search

+3
View File
@@ -1,3 +1,6 @@
// v1.4.34 web-freeze. Schema is locked additive-only until iOS launch
// + v1.5.0 marker. See .planning/v15-strategic-plan.md §2.
generator client {
provider = "prisma-client"
output = "../src/generated/prisma"