-
Notifications
You must be signed in to change notification settings - Fork 657
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
isFromCache
is potentially confusing
#5799
Comments
Thanks for reporting! That's a good point. I think in v3 it was potentially less confusing since if you had a cache miss it usually meant you didn't have a response, but an exception (but not always thanks to In v4 of course now you'll have a response, and the current implementation of It looks like what you really want is At least we need to add a KDoc on |
After talking a bit with @martinbonnin we think keeping |
I think that's definitely the preferable approach here! By default if you're migrating from v3 to v4 with the v3 exception handling enabled, my guess is that you won't be affected by it at all (unless you also have
I will need to double check, but I seem to remember that while |
Good one! I opened #5805 with that. |
@rohandhruva do you mind ellaborating a bit more on what do you use if (response.data != null) {
// Handle (potentially partial) data
} else {
// Do you use `isFromCache` here?
} |
Sure -- the main use case here is logging. We use One of the things we track is the time it took to read data from the cache. This is logged even if it's a cache miss, because that information helps us determine how long the cache lookup took. More generally, though, since |
Makes sense. Are you using CacheInfo for this? CacheInfo was made specifically for those use cases and gives a lot more information than just
I'm trying to account for a future where Also, the cache can be seen as a GraphQL execution service in itself and we could have partially cached data as well at some point. All in all, I'm really not against changing the meaning of |
Not yet, but I can definitely look into it. However, I've also noticed that
In that future, if we are trying to match the current APIs, I would imagine we'll have something like I know it's generalizing based on the current view of the APIs, but in general, I think we need
I don't think it necessarily conflicts with |
Re: cache timing information, if we could find a proper API to do so, I think it'd be a big win. I know @AdamMTGreenberg was also looking into it at some point (see #3221). Maybe Re: I know it's very prospective stuff and I don't want to bikeshed this too much so if #5805 makes things clearer in the current situation, I'm all in for merging it 👍 |
PS: I'll probably die on the
|
I agree with your general approach to That said, if we do eventually support partial responses from the cache at some point in the future, I think there's value in indicating this to the UI somehow. Maybe in that case |
That would be the idea
Is the intent to skip the loading indicator if a cache response is present to avoid a blinking effect? flow.collect {response ->
if (response.data == null) {
// we got a cache miss, display a progress bar while we go to the network
showProgressBar = true
}
} |
Do you have any feedback for the maintainers? Please tell us by taking a one-minute survey. Your responses will help us understand Apollo Kotlin usage and allow us to serve you better. |
Version
3.x-4.0.0-beta.5
Summary
ApolloResponse
has an extension function,isFromCache
. When usingFetchPolicy.CacheFirst
, if there's a cache miss, anApolloResponse
is emitted wheredata == null
andit.exception
is aCacheMissException
. For this response, I would expect thatisFromCache
returnsfalse
. This is because it relies onisCacheHit
beingtrue
, which is not the case for this response. Link to codeI think it'd be ideal to make it return
true
, but I'm not sure if we can change this API now. Maybe we can introduce a new API,isResponseFromCache
that does not rely oncacheHit
beingtrue
, perhaps it returnsisCacheHit || it.exception is CacheMissException
?Steps to reproduce the behavior
No response
Logs
The text was updated successfully, but these errors were encountered: