Unable to get caching working #1831
-
My expectation is that after my api returns data for a given query key, that react-query won't hit my api again for that same query key for at least some period of time. I have tried setting cacheTime with no change in behavior. My api gets hit every time. I assume i must be doing something wrong. The below codesandbox is the simplest way I can try and demonstrate my issue. Using the react-query devtools, my query never shows as fresh, it is always stale or inactive. This is linked to a public API but on mine i can see it is being hit each time the button is clicked even though the key is the same value. Thanks again for any assistance!!! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 7 replies
-
this is what |
Beta Was this translation helpful? Give feedback.
this is what
staleTime
is for. I’ve written about the difference between staleTime and cacheTime here: https://tkdodo.eu/blog/practical-react-query#the-defaults-explained