-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
API for clearing cache #28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
One way of getting around this is by using variables in your calls that key to that user.
Tanner Linsley
…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.
|
Released in version |
@tannerlinsley Thanks! I've checked it, and it looks like clearing Looks like query state should be set to initial query state on clear: Also, stale timeout should be cleared as well. What do you think? I can submit a PR |
Yeah that would be great.
Tanner Linsley
…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. |
@tannerlinsley |
Delete every query
Tanner Linsley
…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.
|
The problem
There's a scenario, which is pretty common:
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:
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: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
The text was updated successfully, but these errors were encountered: