1.0 KiB
1.0 KiB
Architect — F-027 Caching layer with explicit contracts
Feature
F-027 wraps hot catalog reads with Redis cache entries that document key, TTL, invalidation and source of truth.
Design
Module boundaries
Create project/src/modules/cache/ with domain/application/infrastructure/api/tests. Cache is an in-process wrapper around a Redis-like adapter. PostgreSQL remains the source of truth.
Adapter
InMemoryCacheAdapterfor v1 implementingget/set/invalidateand a metrics hook (hit_ratio).
Public API
GET /cache/contractsadmin returns the list of registered cache entries with key, TTL, source.GET /cache/metricsreturns hits/misses.
Cache entries
product:{slug}(TTL 5m, invalidated byProductUpdatedevent)category:{slug}(TTL 5m)nav:tree(TTL 10m)search:popular(TTL 1m)
Acceptance trace
- Catalog update invalidates
product:{slug}andcategory:{slug}. - Redis down -> reads still served from PostgreSQL via bypass.
- Hit ratio metric exposed on
/cache/metrics.