-
I really don't know what is use case of staleTime and cacheTime and what is different |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 22 replies
-
It does get people confused sometimes, which is why I tried to clear that up in a blog post: https://tkdodo.eu/blog/practical-react-query#the-defaults-explained
there is also a very good example in the docs: https://react-query.tanstack.com/guides/caching |
Beta Was this translation helpful? Give feedback.
-
After reading some post, let me try to clear difference. |
Beta Was this translation helpful? Give feedback.
-
Given the defaults with It allows to limit the amount of HTTP queries sent in background. Imagine a component that is remounted and mounted back again within Q-1: Will the cached data be reused in component? Yes, default Q-2: Will an HTTP request to refresh the data be triggered? It depends on
Now you can mentally replace "remount" with "window/tab refocus" and the above explanation will stay true. Extra tips/conclusions from the above:
R-Q Dev. Tools helped me to clarify the above for myself. I highly recommend to play with it for exploration purposes. |
Beta Was this translation helpful? Give feedback.
-
@TkDodo i've set a My apps does the initial fetch for Then 2 seconds later (so 8 seconds before the stale time), the same query is done with a parameter "Liliaceae"... Which means the following key: Since it's not the same key (there is a parameter), I would have expect react-query to fetch immediatly instead of waiting 8 seconds for the cache entry to be stale. I don't understand how parameterized queries can benefit from Is it the expected behavior? I am new to react-query so maybe i've missed something? Thanks for your help! Patrick |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
then i have a question why react query set default time at cacheTime to five minutes and staleTime to 0 second? and where react query save cache data at computer? cache memory or disk memory? and if staleTime is gone, react query request to server, if response data is same with react query's cache data. in this situation how react query doing? unconditional change cache data to server data? or compare with react query cache data and server data? |
Beta Was this translation helpful? Give feedback.
It does get people confused sometimes, which is why I tried to clear that up in a blog post: https://tkdodo.eu/blog/practical-react-query#the-defaults-explained