Repeat after me: 📝Invalidation does not remove cached data Generally, @tan_stack React Query only ever removes data from your cache for garbage collection, or if you manually remove it (with removeQueries). Invalidation just marks it as stale so that we can refetch it.

Oct 31, 2024 · 2:09 PM UTC

12
23
351
24,882
Sort replies: Relevant Recent Liked
Replying to @TkDodo @tan_stack
Took me a while to get this. I was expecting the data to be removed and re-renders to get triggered all over. Sort of like a change in a Context.
1
5
1,169
If you want that, use resetQueries instead
1
7
965
Replying to @TkDodo @tan_stack
Does "refetch" here mean retrieve from cache or re-run query if necessary? To me word "fetch" usually implies an API or any external call so this statement confuses me a bit 😅
1
3
1,192
Yes, refetch means the queryFn runs again.
1
4
861
Replying to @TkDodo @tan_stack
Why not rename it markStaleQueries instead?
1
4
1,583
Because it also refetches active queries right away.
4
940
Replying to @TkDodo @tan_stack
So does invalidation keep the old queries cached?
1
1
301
It refetches active queries that match and marks the rest as stale so that they get refetched when they are used the next time. But during refetching, it keeps stale data available.
1
2
187
Replying to @TkDodo @tan_stack
When invalidate queries marks as stale and re-fetches the data, does it trigger a re-render?
1
2
1,191
"Depends". It re-renders if it needs to, e.g. if you use the isFetching flag or if the refetch yields new data. We are pretty optimized in this regard.
7
694
Replying to @TkDodo @tan_stack
oh, that's an interesting one. googled up and: - varnish site says exactly like you - wikipedia and many others explain "invalidation" as removal or at least replacement Guess you cannot convince everyone to align - and have to explicitly define "invalidation" for @tan_stack
1
1
372
varnish site 😅?
1
290
Replying to @TkDodo @tan_stack
People really don't read docs
2
116
Replying to @TkDodo @tan_stack
Cache is your greatest adversary and largest foe all at the same time. I give a talk”why does my cache hate me” to help people understand this contentious relationship.
2
280
Replying to @TkDodo @tan_stack
1
1
1
114
Replying to @TkDodo @tan_stack
People should have another look on the docs. Not understanding this makes you miss the whole point of the library
2
300
Replying to @TkDodo @tan_stack
non
1
122