T
TanStack3y ago
deep-jade

Cache not clearing with removeQueries()

I am calling queryClient.removeQueries() before logging out. However, I still see the cache has data. What could I be doing wrong?
8 Replies
compatible-crimson
compatible-crimson3y ago
Are you calling it with queryKeys? Pretty sure that requires queryKeys and what you might want is queryClient.clear() instead. I actually ran into a similar problem with forgetting to clear zustand stores which lead me to full page redirect after logout. Felt like a nice way to sanity cleanse my app.
deep-jade
deep-jadeOP3y ago
Oh I see. Will try! Thanks Still facing this issue .clear() also dosen't work
sensitive-blue
sensitive-blue3y ago
Show a reproduction
deep-jade
deep-jadeOP3y ago
Not v sure about how to do that.. I can paste code that I am using but it is really as basic as useQuery(...) to store in the cache and then queryClient.removeQueries() to clear the cache before logging out
sensitive-blue
sensitive-blue3y ago
Show logout code
deep-jade
deep-jadeOP3y ago
async function logOut() {
posthog.reset();
queryClient.removeQueries();
await app.currentUser?.logOut();
setCurrentUser(app.currentUser);
}
async function logOut() {
posthog.reset();
queryClient.removeQueries();
await app.currentUser?.logOut();
setCurrentUser(app.currentUser);
}
provincial-silver
provincial-silver3y ago
removeQueries will remove data from the cache - you can see that if you use the devtools. It will not re-render your app (because that would likely trigger useQuery to re-run since there is no data in the cache anymore).
deep-jade
deep-jadeOP3y ago
I'm seeing the cache using the dev tools and I still see data in the cache after logging out. Not quite sure what's going on Found the issue! I should have been clearing the cache after logging out so that none of the queries would be re-fetched

Did you find this page helpful?