You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a question regarding the relationship between QueryObserver and queryCache.clear() in React Query.
I created a new QueryObserver and subscribed to it using the subscribe method.
I then called queryCache.clear() to remove all cache.
After that, I updated the query data using setQueryData, but I noticed that the existing observer did not emit the new data.
So I created another new QueryObserver and subscribed again, which worked as expected.
However, I later found that the original observer (which had already been "removed") emitted the old cached data once the staleTime of 10 minutes passed.
Questions:
Is it an expected behavior that an observer continues to emit data based on staleTime, even after queryCache.clear() is called?
If this is intentional, does it mean we must manually unsubscribe existing observers before calling queryCache.clear() to avoid this?
Am I missing something in my understanding of how queryCache.clear() interacts with observers?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hello,
I have a question regarding the relationship between QueryObserver and queryCache.clear() in React Query.
I created a
new QueryObserver
and subscribed to it using thesubscribe
method.I then called queryCache.clear() to remove all cache.
After that, I updated the query data using setQueryData, but I noticed that the existing observer did not emit the new data.
So I created another
new QueryObserver
and subscribed again, which worked as expected.However, I later found that the original observer (which had already been "removed") emitted the old cached data once the staleTime of 10 minutes passed.
Questions:
Thanks in advance for the clarification!
Beta Was this translation helpful? Give feedback.
All reactions