-
Notifications
You must be signed in to change notification settings - Fork 662
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
Fix item wrongly removed from http cache when error in subscriptions #4537
Conversation
…a subscription was in error
✅ Deploy Preview for apollo-android-docs canceled.
|
The root problem seems to be that |
Good point! Hmm, we could store the |
Mmmmm right. The issue is that the cache key is computed at the HTTP layer but we're reading it at the GraphQL layer. You could maintain a map |
@@ -72,16 +73,19 @@ fun ApolloClient.Builder.httpCache( | |||
directory = directory, | |||
maxSize = maxSize, | |||
) | |||
var cacheKey: String? = null | |||
val apolloRequestToCacheKey = mutableMapOf<String, String>() | |||
var apolloRequestUuid: Uuid? = null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is still racy. This code can be accessed from multiple threads. requestUuid
needs to be passed down to the interceptor and apolloRequestToCacheKey
protected by a lock
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right of course! 👍 A fix in 152e746.
...pollo-http-cache/src/main/kotlin/com/apollographql/apollo3/cache/http/HttpCacheExtensions.kt
Outdated
Show resolved
Hide resolved
Hi @BoD, |
Hi @sam43, thanks a lot for the feedback, glad that the fix works for you! We've just released v3.7.2 which includes the fix. Thanks again for reporting the issue 🙏 |
Issue encountered here.
For the http cache, we add 2 interceptors:
HttpInterceptor
that deals with cachingApolloInterceptor
which cleans up the cache if there was an errorThe cache key is computed in 1. and used in 2. But 1. is executed for queries and mutations only, whereas 2. is also executed for subscriptions. When a subscription resulted in an error, an arbitrary (the most recent one) cache key would be incorrectly cleared from the cache. The proposed fix is to do this cleanup only for queries and mutations.