apollo-cache-persist: client.clearStore() or client.resetStore() do nothing
Calling either await client.clearStore() or await client.resetStore() do nothing.
My localstorage persisted cache doesn’t change. Why?
I think it should remove persisted cache in localStorage, isn’t it?
A bug?
"apollo-cache-inmemory": "1.5.1",
"apollo-cache-persist": "0.1.1",
"apollo-client": "2.5.1",
"apollo-link": "1.2.11",
"apollo-link-context": "1.0.17",
"apollo-link-error": "1.1.10",
"apollo-link-http": "1.5.14",
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 4
- Comments: 20
The idea to improve that is to hook into InMemory cache clear method and perform persistor clear. It will be little bit hacky and it will work for InMemoryCache but it will provide more seamless behavior that developers will expect.
Please add +1 if you would like to have this in our Roadmap
@wtrocki Thanks!
So for now it looks like I need to manually call
persistor.purge()afterclearStore(). I need to do the purge deep inside my Logout component in React. The Logout.js example below seems to work but is there any downside?src/index.js
Logout.js
It happens when clearStore is not awaited. Proper handler:
Can cause issues:
I think we simply need to hook to cache.clear method and call persistor.purge. This simple fix is going to resolve issue. Any contribution welcome as I would need to review it and approve it
@frederikhors I have done example app to show how this can be done: https://codesandbox.io/embed/basic-apollo-app-hiis7?codemirror=1
If we do not wait we going to get these nasty timing issues where persistence will be cleared but it can still get hot InMemCache object.
No problem with that. The fix that we talking about was to just wrap both into a single method so actual behavior should be the same.
Snippet for logout should look like this
What will be your Apollo Client version? Apollo client changed a little for localstate stuff and the issue may be there. The version of cache-persist did not change for 2 years.
https://github.com/apollographql/apollo-client/blob/58cb6d5437c00e42487052b727eb30190e31fbad/packages/apollo-client/src/core/QueryManager.ts#L913