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
On Nov 9, 2019, 9:46 AM -0700, Andrew Cherniavskii ***@***.***>, wrote:
The problem
There's a scenario, which is pretty common:
• user logs in
• some user data is fetched
• user logs out
• different user logs in and for a moment sees previous user's data
Normally, all user data should be deleted after log out, but there's no API for that at the moment.
I've tried setQueryData function to clear some queries, but it didn't work for me, since it doesn't make those query stale.
I've managed to clear cache like this:
import { queries } from 'react-query';
function handleLogout() {
queries.length = 0;
}
But I'm not sure if it is safe to do this, since this is not a public API.
Proposed solution
Introduce clearQueries function, which will:
• clear all queries if called without arguments
• clear all queries except those provided as first argument.
The second option may be useful for applications, which are partly public. This will allow to clear user data cache, but keep public data cache.
Let me know do you think about that
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.
I've checked it, and it looks like clearing state.data might not be enough.
Consider case, when staleTime !== 0, and clearQueryCache is called.
Then, new data won't be fetched until query is marked as stale.
Looks like query state should be set to initial query state on clear:
On Nov 12, 2019, 3:13 AM -0700, Andrew Cherniavskii ***@***.***>, wrote:
@tannerlinsley Thanks!
I've checked it, and it looks like clearing state.data might not be enough.
Consider case, when staleTime !== 0, and clearQueryCache is called.
Then, new data won't be fetched until query is marked as stale.
Looks like query state should be set to initial query state on clear:
https://github.com/tannerlinsley/react-query/blob/b89576713282351a9b620decb50145fc7a426c82/src/index.js#L64-L73
Also, stale timeout should be cleared as well.
What do you think? I can submit a PR
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.
Actually. Just delete all of the entries all the time. If a query is rerun and can’t find a query, it will get instantiated as needed. No need to be specific I think.
On Nov 12, 2019, 1:07 PM -0700, Andrew Cherniavskii ***@***.***>, wrote:
> Just delete all of the entries all the time
@tannerlinsley
Do you mean delete all state entries for every query or delete all entries of queries array?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.
Activity
tannerlinsley commentedon Nov 9, 2019
tannerlinsley commentedon Nov 11, 2019
Released in version
0.3.7🎉cherniavskii commentedon Nov 12, 2019
@tannerlinsley Thanks!
I've checked it, and it looks like clearing
state.datamight not be enough.Consider case, when
staleTime!== 0, andclearQueryCacheis called.Then, new data won't be fetched until query is marked as stale.
Looks like query state should be set to initial query state on clear:
https://github.com/tannerlinsley/react-query/blob/b89576713282351a9b620decb50145fc7a426c82/src/index.js#L64-L73
Also, stale timeout should be cleared as well.
What do you think? I can submit a PR
tannerlinsley commentedon Nov 12, 2019
tannerlinsley commentedon Nov 12, 2019
Actually. Just delete all of the entries all the time. If a query is rerun and can’t find a query, it will get instantiated as needed. No need to be specific I think.
cherniavskii commentedon Nov 12, 2019
@tannerlinsley
Do you mean delete all state entries for every query or delete all entries of
queriesarray?tannerlinsley commentedon Nov 12, 2019