React · Middle · Question 42 of 75
How does staleTime differ from gcTime in TanStack Query?
- ✓Correct answer:
staleTimeis the freshness period,gcTimehow long it's kept without observers - 2They're synonyms:
gcTimeis the new name ofstaleTimein v5 - 3
staleTimeis the request timeout,gcTimethe retry interval
Explanation
While data is fresh, there's no refetch on mount or window focus. After staleTime, it becomes stale but is still shown from the cache and refreshed in the background. gcTime (formerly cacheTime, 5 minutes by default) starts counting when the query has no observers left - then the data is removed from memory.