Execution — fw-09-query-cache

Steps extracted from CONCEPTS.md. Read the concepts first; this file is the doing.

Record results in observation.md; tick checkpoints in verification.md.


3. Build order

  1. Key normalisation (structural equality, stable ordering).
  2. Cache with status: fresh | stale | fetching | error.
  3. Deduplication: N simultaneous subscribers, one request.
  4. Stale-while-revalidate.
  5. Retries with backoff; distinguish retriable from terminal errors.
  6. Cancellation on unsubscribe.
  7. Invalidation, exact and by key prefix.
  8. Background refetch (focus, reconnect, interval).
  9. Optimistic updates with rollback.
  10. Garbage collection of unobserved entries.
  11. Pagination and dependent queries.

4. Failure Lab — build every race

  1. Out-of-order responses. Request A then B for the same key; A resolves last. Show A's data winning. Fix with a sequence number; explain why timestamps are insufficient.
  2. Optimistic rollback onto a changed base. Apply an optimistic update, then a different server update arrives, then the optimistic one fails. Roll back to what?
  3. Dedup + cancellation. Three subscribers share one request; one unsubscribes. Does the request abort? Should it?
  4. Refetch storm. Window focus triggers refetch of 50 queries simultaneously.
  5. GC race. An entry is collected while a component is mid-mount.
  6. Cross-tab. Two tabs, same key, one mutates.