Cache Control Overview
TanStack Query
Client memory caching staleTime/gcTime
HTTP Cache
Cache-Control headers CDN/Browser caching
Revalidation
Auto/manual refresh Keep data fresh
Performance
Fast response Reduced server load
TanStack Query Client Caching
Basic Configuration
staleTime vs gcTime
Per-Query Cache Settings
Pass options to Service Hook for individual settings.Caching Strategy by Data Type
Manual Cache Control
Cache Invalidation
Direct Cache Update
Cache Query
SSR Cache-Control
You can set HTTP Cache-Control headers in registerSSR.Individual Route Caching
Caching Strategy Examples
CacheControlConfig Type
Global Caching Handler
Set a global handler that applies to all SSR routes.Hybrid Caching
Use SSR and client caching together.- Browser HTTP cache: 1 hour (max-age=3600)
- TanStack Query memory: 5 minutes (staleTime)
- Server SSR rendering: Render on cache miss
- First visit: SSR → HTML + data → Store in browser cache
- Re-visit within 5 min: Use TanStack Query memory cache
- 5 min ~ 1 hour: Use browser HTTP cache
- After 1 hour: New request to server
Development Environment Debugging
React Query Devtools
Check Cache State
Check HTTP Cache Headers
Check response headers in Browser Developer Tools → Network tab:Performance Optimization Strategies
1. Use Subsets
Cache only needed fields to save memory:2. Selective Revalidation
Actively revalidate only important data:3. Cache Prefetching
Pre-cache data that will be needed next:Cautions
Next Steps
SSR Setup
SSR basic structure
Data Preloading
How to use registerSSR
Hydration Strategies
Hydration optimization
TanStack Query Docs
Query detailed guide