Cache Invalidation and SWR

Balance perceived performance and correctness with stale-while-revalidate flows.

Pattern level: macro

TL;DR

Serve cached content instantly, then revalidate in background with precise invalidation keys.

Decision criteria

  • High-read products benefit from SWR defaults.
  • Mutation-heavy surfaces need focused invalidation paths.

Testing + Accessibility Rubric

CategoryLevelRequirementDone When
functionalunitState transitions handle loading, success, empty, and error.Reducer/state machine tests cover all transitions.
functionalintegrationClient correctly maps API contracts into UI-ready view models.Contract fixtures pass with no runtime shape mismatch.
a11yintegrationFull keyboard flow works for primary interaction loop.Tab/Shift+Tab/Enter/Escape scenarios pass for critical controls.
a11ye2eDynamic updates expose meaningful live region announcements.Manual SR checks validate announcement timing and text quality.

Used In Case Studies

Related Patterns