feat(cache): in-process catalogue cache with version invalidation (#22) #117
No reviewers
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
primatekuntech/kws!117
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/22-catalog-cache"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What
A per-node in-process response cache in front of 17 public catalogue GETs, invalidated within seconds by a PostgreSQL sequence that admin writes bump (#22).
api/internal/cache: bounded map (1,000 entries, 256 KiB per body, 60 s TTL), aWrapmiddleware that stores finished 200 responses of opted-in routes and replays them (ETag/304 identical to the live handler,Ageheader on hits), and a watcher that polls the version every 2 s and clears the cache when it moves.catalog_cache_versionand a statement-level trigger (INSERT/UPDATE/DELETE/TRUNCATE) on the 18 tables the cached routes read. A sequence, not a counter row, so admin transactions cannot deadlock on it.app.CachedRoutes(one list of 17 patterns) attached throughhttpapi.WithRouteMiddleware; no module'sRegisterRouteschanged. API mode only;KWS_CACHE=offserves live./v1/admin,/v1/me, seat availability, sales, wallets, payments, tickets, image bytes.Why
Groundwork for the 1k-user target (docs/02 section 6 rule 4): public catalogue reads that miss Cloudflare and Caddy should not reach the database, and a second node must refresh after an admin edit.
Verification
make cover: 91.1% (minimum 80%;internal/cacheandinternal/cache/pgstore100%);make lint0 issues;make contractok;go test -race -count=1 ./...ok; client generation unchanged.Rulings I made
Ageheader on hits, escaped-path key, direct sequence read.no-store/privateresponses (none are sent today).internal/cache/middleware.goinapi/.golangci.yml(kept by the owner's decision; a hook here blocks inlinenolint).Owner please check ([verify] in ADR 0026)
pg_restore -xwould make reads fail loudly, not silently).Not verified
Real load (#61); Cloudflare/Caddy behaviour with the
Ageheader; a two-node setup; the restricted-role test needs a superuser test DB user (the CI postgres image and the dev DB are).🤖 Generated with Claude Code