diff --git a/libraries/apollo-http-cache/api/apollo-http-cache.api b/libraries/apollo-http-cache/api/apollo-http-cache.api index 91972169927..49aad416284 100644 --- a/libraries/apollo-http-cache/api/apollo-http-cache.api +++ b/libraries/apollo-http-cache/api/apollo-http-cache.api @@ -7,7 +7,6 @@ public abstract interface class com/apollographql/apollo3/cache/http/ApolloHttpC public final class com/apollographql/apollo3/cache/http/CachingHttpInterceptor : com/apollographql/apollo3/network/http/HttpInterceptor { public static final field Companion Lcom/apollographql/apollo3/cache/http/CachingHttpInterceptor$Companion; - public fun (Lcom/apollographql/apollo3/cache/http/ApolloHttpCache;)V public fun (Ljava/io/File;JLokio/FileSystem;)V public synthetic fun (Ljava/io/File;JLokio/FileSystem;ILkotlin/jvm/internal/DefaultConstructorMarker;)V public final fun getCache ()Lcom/apollographql/apollo3/cache/http/ApolloHttpCache; @@ -31,6 +30,7 @@ public final class com/apollographql/apollo3/cache/http/DiskLruHttpCache$Compani } public final class com/apollographql/apollo3/cache/http/HttpCache { + public static final fun configureApolloClientBuilder (Lcom/apollographql/apollo3/ApolloClient$Builder;Lcom/apollographql/apollo3/cache/http/ApolloHttpCache;)Lcom/apollographql/apollo3/ApolloClient$Builder; public static final fun configureApolloClientBuilder (Lcom/apollographql/apollo3/ApolloClient$Builder;Ljava/io/File;J)Lcom/apollographql/apollo3/ApolloClient$Builder; public static final fun getHttpCache (Lcom/apollographql/apollo3/ApolloClient;)Lcom/apollographql/apollo3/cache/http/ApolloHttpCache; public static final fun httpDoNotStore (Lcom/apollographql/apollo3/api/MutableExecutionOptions;Z)Ljava/lang/Object; diff --git a/libraries/apollo-http-cache/src/main/kotlin/com/apollographql/apollo3/cache/http/CachingHttpInterceptor.kt b/libraries/apollo-http-cache/src/main/kotlin/com/apollographql/apollo3/cache/http/CachingHttpInterceptor.kt index d6b1228a4cc..aee15a6829c 100644 --- a/libraries/apollo-http-cache/src/main/kotlin/com/apollographql/apollo3/cache/http/CachingHttpInterceptor.kt +++ b/libraries/apollo-http-cache/src/main/kotlin/com/apollographql/apollo3/cache/http/CachingHttpInterceptor.kt @@ -17,7 +17,7 @@ import java.io.File import java.time.Instant import java.time.format.DateTimeParseException -class CachingHttpInterceptor( +class CachingHttpInterceptor internal constructor( private val lruHttpCache: ApolloHttpCache ) : HttpInterceptor { diff --git a/libraries/apollo-http-cache/src/main/kotlin/com/apollographql/apollo3/cache/http/HttpCacheExtensions.kt b/libraries/apollo-http-cache/src/main/kotlin/com/apollographql/apollo3/cache/http/HttpCacheExtensions.kt index 8b609e90cc4..006c4bd7f2c 100644 --- a/libraries/apollo-http-cache/src/main/kotlin/com/apollographql/apollo3/cache/http/HttpCacheExtensions.kt +++ b/libraries/apollo-http-cache/src/main/kotlin/com/apollographql/apollo3/cache/http/HttpCacheExtensions.kt @@ -26,6 +26,7 @@ import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.flowOn import kotlinx.coroutines.flow.onCompletion import kotlinx.coroutines.flow.onEach +import okio.FileSystem import java.io.File enum class HttpFetchPolicy { @@ -72,10 +73,15 @@ fun ApolloClient.Builder.httpCache( directory: File, maxSize: Long, ): ApolloClient.Builder { - val cachingHttpInterceptor = CachingHttpInterceptor( - directory = directory, - maxSize = maxSize, - ) + return httpCache(DiskLruHttpCache(FileSystem.SYSTEM, directory, maxSize)) +} + +@JvmName("configureApolloClientBuilder") +fun ApolloClient.Builder.httpCache( + apolloHttpCache: ApolloHttpCache, +): ApolloClient.Builder { + val cachingHttpInterceptor = CachingHttpInterceptor(apolloHttpCache) + val apolloRequestToCacheKey = mutableMapOf() return addHttpInterceptor(object : HttpInterceptor { override suspend fun intercept(request: HttpRequest, chain: HttpInterceptorChain): HttpResponse {