Skip to content

Commit

Permalink
Add ApolloClient.Builder(ApolloHttpCache)
Browse files Browse the repository at this point in the history
  • Loading branch information
martinbonnin committed Feb 21, 2024
1 parent f79b5f5 commit 8a819d1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion libraries/apollo-http-cache/api/apollo-http-cache.api
Original file line number Diff line number Diff line change
Expand Up @@ -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 <init> (Lcom/apollographql/apollo3/cache/http/ApolloHttpCache;)V
public fun <init> (Ljava/io/File;JLokio/FileSystem;)V
public synthetic fun <init> (Ljava/io/File;JLokio/FileSystem;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun getCache ()Lcom/apollographql/apollo3/cache/http/ApolloHttpCache;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<String, String>()
return addHttpInterceptor(object : HttpInterceptor {
override suspend fun intercept(request: HttpRequest, chain: HttpInterceptorChain): HttpResponse {
Expand Down

0 comments on commit 8a819d1

Please sign in to comment.