Maintenance cache lifecycle
Role
Maintenance cache accelerates list and detail reads for maintenance_requests, aligned with MaintenanceCacheService (or successor) in apps/worker.
This document states behavioral contracts; wiring details live in code and ../../architecture/cache-multi-shard-summary.md where relevant.
Write path (mutations)
- Always persist to the database first (source of truth).
- On success:
- Invalidate or replace cache entries for:
- The specific request (by id).
- Any list or aggregated cache keys that include this request (department lists, user dashboards, etc.).
- Invalidate or replace cache entries for:
- Terminal transitions that write
finalSnapshotmust commit atomically with the row update (see ../maintenance/snapshot-behavior.md).
Read path
- On read, prefer cache if valid for the requested scope (detail by id, filtered list).
- On cache miss, load from DB, optionally hydrate
relatedUsersfor open tasks via user.md, then store in cache per TTL/policy.
Closed tasks
- List: Do not ship full
finalSnapshot; expose list fields +takenAtper ../maintenance/snapshot-behavior.md. - Detail: Return full
finalSnapshotfor closed rows.
Purge
Hard delete removes the row and must:
- Remove or invalidate all cache keys pointing at that id (detail, lists, aggregates).