apollo-kotlin
apollo-kotlin copied to clipboard
Support `CacheAndNetwork` Option in the `HttpCache`
Use case
To replicate the convenient functionality of using the normalized cache, the HttpCache
should also support this option. Currently, it only supports CacheFirst
, or NetworkFirst
, which means we only ever receive one response, if its in the cache.
Currently, what this means, is if, we use HttpCache
without a timeout specified, the cache never expires. It never hits the network again after it receives the initial response, unless I set an explicit timeout. I'd certainly like to cache the previous output and still reach out for the latest - this way the UI can reactively update if the data changes in any meaningful way.
A workaround is to send two queries - 1 for initial cache, then a second one with cache disabled on that request.
Describe the solution you'd like
Ideally, using watch()
on our queries, we could receive multiple results. 1 for cache (if it exists), then 1 for the network (if we have a network connection).
Add the CacheAndNetwork
option to the HttpFetchPolicy
. Optionally, merge the two enums so they are both equally supported in each cache type.