-
Notifications
You must be signed in to change notification settings - Fork 118
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
listen to cache changes when using FetchPolicy.NetworkOnly #579
base: master
Are you sure you want to change the base?
listen to cache changes when using FetchPolicy.NetworkOnly #579
Conversation
✅ Deploy Preview for verdant-brigadeiros-5171fa canceled.
|
4d32e16
to
3eddbf4
Compare
Yes, there are good reasons to do that. Say, you have And you periodically poll for the latest posts using .NetworkOnly. If the response contains a post with the ID that is watched by the .NetworkOnly ist mostly useful to update other listeners automatically without having to do state management manually. |
Yes, exactly. But isn't that something expected that you want to have newest version of the post? Why would you like to stick with the old one? As you can remember I had a query with CacheAndNetwork policy and I was calling the same request with NetworkOnly policy in case of pull to refresh action, but then any changes in cache don't propagate. So what do you think about adding an additional FetchPolicy type? Like 'NetworkOnlyWithUpdates'. In case of my project I've overridden default FetchPolicyTypedLink to a custom one. |
I don't quite understand. Writing the .NetworkOnly response to the cache is what causes the other listeners to update. This is also the behaviour of Apollo, from which we adopted the FetchPolicies.
Yes. This is quite the unfortunate behaviour of using the Refetching/ Pagination feature together with watching the cache.
That's something I think is reasonable. Changing Adding type to an enum would also be breaking (in case someone depends on exhaustive matching for example), but probably very low impact. |
Do you mean on my side or in the Ferry?
Yes, I totally agree. But for the beginning, I wanted to show the problem and possible solution, so I've modified the existing policy because it's faster than creating a new one.
Sure, so just let me know if I should prepare a PR with the new FetchPolicy or leave it for now if you decide that's not needed. P.S. I see that Apollo has something called nextFetchPolicy. I am not sure if it solves my problem, but could be. |
In Ferry. It's clear that the refetching/paging API using the requestcontroller and the cache do not play well together.
Thanks! At the moment, I think a new fetch policy makes more sense. But let me take some time to review the approach of apollo. |
Sure 😊 |
Hi! 👋
Issue
That PR solves the problem I described here #574.
The problem is that when we use
FetchPolicy.NetworkOnly
and something in the cache changes (e.g. with use ofwriteFragment
method) that relates to our query then that change will not emit a new event for the query. (That happens forCacheAndNetwork
andCacheFirst
policies).I am not sure whether it should work like that, because I cannot find any reason to save the response to the cache, but do not listen for the changes in the cache.
So if there is any reason for that then please let me know. In that case, maybe it would be beneficial to add another FetchPolicy?
Solution
I added listening for changes in the cache when using
FetchPolicy.NetworkOnly
and added a tests explaining the usage of it.