Issue in understanding one of the examples in tanstack/query (playground example)
Hi all, I was playing with the example in the docs https://tanstack.com/query/latest/docs/framework/react/examples/playground
we are setting gcTime explicitly in the
for all the queries showing in the devTools, it seems gcTime is not taking effect, checked from devTools, its showing as default of 5 mins(ideally it should be what we have set from the textbox)
can someone help me figure this out why its not being set by the useEffect?
TanStack | High Quality Open-Source Software for Web Developers
Headless, type-safe, powerful utilities for complex workflows like Data Management, Data Visualization, Charts, Tables, and UI Components.

6 Replies
equal-aqua•10mo ago
For new or existing cache entries?
I'm pretty sure defaults are like a cloned snapshot on each query, so changing defaults won't affect something already in the cache (unless it's refetched). You should see new cache entries with your correct defaults.
fair-roseOP•10mo ago
thanks, will check this again.
it seems fine for the new queries, i.e. new defaults are being set for new queries. but for the old ones, they are not being updated even after refetch.
equal-aqua•10mo ago
I did a quick POC test in our app and it seemed to work, but we have stale Infinity and gcTime 0 so it was tough to be sure
Thinking on my POC, it was actually a bad test because I was changing queryKeys therefore cache entries
You could try
resetQueries
?fair-roseOP•10mo ago
ok that is fine. this was just for my learning, I didn't have this mental model where the gcTime will not be updated for old queries, I thought since queryClient is applicable for entire cache and hence all the queries.
Thanks for your inputs 🙂
equal-aqua•10mo ago
I think because you can also specify things like
gcTime
on a per useQuery
basis, it has to be stored per cache entryother-emerald•10mo ago
defaults only apply to new queries, not retroactively on already created ones