Skip to content
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

Ignore IOException when calling ApolloHttpCache.remove #5730

Merged
merged 1 commit into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import okio.Buffer
import okio.ByteString.Companion.toByteString
import okio.FileSystem
import java.io.File
import java.io.IOException
import java.time.Instant
import java.time.format.DateTimeParseException

Expand Down Expand Up @@ -141,7 +142,10 @@ class CachingHttpInterceptor(

val expireAfterRead = request.headers.valueOf(CACHE_EXPIRE_AFTER_READ_HEADER)?.lowercase() == "true"
if (expireAfterRead) {
lruHttpCache.remove(cacheKey)
try {
lruHttpCache.remove(cacheKey)
} catch (_: IOException) {
}
}

val timeoutMillis = request.headers.valueOf(CACHE_EXPIRE_TIMEOUT_HEADER)?.toLongOrNull() ?: 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.flow.onCompletion
import kotlinx.coroutines.flow.onEach
import java.io.File
import java.io.IOException

enum class HttpFetchPolicy {
/**
Expand Down Expand Up @@ -123,13 +124,19 @@ fun ApolloClient.Builder.httpCache(
catch { throwable ->
// Revert caching of responses with errors
val cacheKey = synchronized(apolloRequestToCacheKey) { apolloRequestToCacheKey[request.requestUuid.toString()] }
cacheKey?.let { cachingHttpInterceptor.cache.remove(it) }
try {
cacheKey?.let { cachingHttpInterceptor.cache.remove(it) }
} catch (_: IOException) {
}
throw throwable
}.onEach { response ->
// Revert caching of responses with errors
val cacheKey = synchronized(apolloRequestToCacheKey) { apolloRequestToCacheKey[request.requestUuid.toString()] }
if (response.hasErrors()) {
cacheKey?.let { cachingHttpInterceptor.cache.remove(it) }
try {
cacheKey?.let { cachingHttpInterceptor.cache.remove(it) }
} catch (_: IOException) {
}
}
}.onCompletion {
synchronized(apolloRequestToCacheKey) { apolloRequestToCacheKey.remove(request.requestUuid.toString()) }
Expand Down
Loading