LOCK
Caching strategies
Resilient data access through client-side caching and intelligent retry patterns. Keep your application responsive even when the network degrades.
Client-side cache
Store fetched data in a local cache — Map, IndexedDB, or a library like SWR. On subsequent requests, serve from cache immediately while revalidating in the background. This eliminates spinner waterfalls and keeps the UI interactive.
- Instant reads from local state — zero network latency for cached keys.
- Stale-while-revalidate: show cached data, fetch fresh in background.
- Deduplicate in-flight requests so concurrent callers share one promise.
Retry-from-cache
When a network request fails, fall back to the last-known-good cached value instead of surfacing an error immediately. Combine with exponential backoff for transient failures, and only escalate to the user when the cache is cold and retries are exhausted.
- Cache stampede protection — serve stale data while refreshing.
- Graceful degradation: users see slightly stale data, not a broken page.
- Circuit breaker integration — stop retrying if the backend is down hard.