Cache Control Overview
TanStack Query
Client memory cachingstaleTime/gcTime
HTTP Cache
Cache-Control headersCDN/Browser caching
Revalidation
Auto/manual refreshKeep data fresh
Performance
Fast responseReduced 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