From 72656ee8d295a268602c0a302826579b3d3570ce Mon Sep 17 00:00:00 2001 From: BoD Date: Thu, 24 Apr 2025 18:17:18 +0200 Subject: [PATCH 01/11] Make SimpleApolloStore.apolloStore public and add GC extensions --- normalized-cache/api/normalized-cache.api | 7 ++++ .../api/normalized-cache.klib.api | 6 ++++ .../cache/normalized/GarbageCollection.kt | 32 +++++++++++++++++++ .../cache/normalized/SimpleApolloStore.kt | 2 +- 4 files changed, 46 insertions(+), 1 deletion(-) diff --git a/normalized-cache/api/normalized-cache.api b/normalized-cache/api/normalized-cache.api index b6eb8c96..6eac01dd 100644 --- a/normalized-cache/api/normalized-cache.api +++ b/normalized-cache/api/normalized-cache.api @@ -121,17 +121,23 @@ public final class com/apollographql/cache/normalized/GarbageCollectResult { public final class com/apollographql/cache/normalized/GarbageCollectionKt { public static final fun allRecords (Lcom/apollographql/cache/normalized/api/NormalizedCache;)Ljava/util/Map; public static final fun garbageCollect-SxA4cEA (Lcom/apollographql/cache/normalized/ApolloStore;Lcom/apollographql/cache/normalized/api/MaxAgeProvider;J)Lcom/apollographql/cache/normalized/GarbageCollectResult; + public static final fun garbageCollect-SxA4cEA (Lcom/apollographql/cache/normalized/SimpleApolloStore;Lcom/apollographql/cache/normalized/api/MaxAgeProvider;J)Lcom/apollographql/cache/normalized/GarbageCollectResult; public static final fun garbageCollect-SxA4cEA (Lcom/apollographql/cache/normalized/api/NormalizedCache;Lcom/apollographql/cache/normalized/api/MaxAgeProvider;J)Lcom/apollographql/cache/normalized/GarbageCollectResult; public static synthetic fun garbageCollect-SxA4cEA$default (Lcom/apollographql/cache/normalized/ApolloStore;Lcom/apollographql/cache/normalized/api/MaxAgeProvider;JILjava/lang/Object;)Lcom/apollographql/cache/normalized/GarbageCollectResult; + public static synthetic fun garbageCollect-SxA4cEA$default (Lcom/apollographql/cache/normalized/SimpleApolloStore;Lcom/apollographql/cache/normalized/api/MaxAgeProvider;JILjava/lang/Object;)Lcom/apollographql/cache/normalized/GarbageCollectResult; public static synthetic fun garbageCollect-SxA4cEA$default (Lcom/apollographql/cache/normalized/api/NormalizedCache;Lcom/apollographql/cache/normalized/api/MaxAgeProvider;JILjava/lang/Object;)Lcom/apollographql/cache/normalized/GarbageCollectResult; public static final fun getReachableCacheKeys (Ljava/util/Map;)Ljava/util/Set; public static final fun removeDanglingReferences (Lcom/apollographql/cache/normalized/ApolloStore;)Lcom/apollographql/cache/normalized/RemovedFieldsAndRecords; + public static final fun removeDanglingReferences (Lcom/apollographql/cache/normalized/SimpleApolloStore;)Lcom/apollographql/cache/normalized/RemovedFieldsAndRecords; public static final fun removeDanglingReferences (Lcom/apollographql/cache/normalized/api/NormalizedCache;)Lcom/apollographql/cache/normalized/RemovedFieldsAndRecords; public static final fun removeStaleFields-SxA4cEA (Lcom/apollographql/cache/normalized/ApolloStore;Lcom/apollographql/cache/normalized/api/MaxAgeProvider;J)Lcom/apollographql/cache/normalized/RemovedFieldsAndRecords; + public static final fun removeStaleFields-SxA4cEA (Lcom/apollographql/cache/normalized/SimpleApolloStore;Lcom/apollographql/cache/normalized/api/MaxAgeProvider;J)Lcom/apollographql/cache/normalized/RemovedFieldsAndRecords; public static final fun removeStaleFields-SxA4cEA (Lcom/apollographql/cache/normalized/api/NormalizedCache;Lcom/apollographql/cache/normalized/api/MaxAgeProvider;J)Lcom/apollographql/cache/normalized/RemovedFieldsAndRecords; public static synthetic fun removeStaleFields-SxA4cEA$default (Lcom/apollographql/cache/normalized/ApolloStore;Lcom/apollographql/cache/normalized/api/MaxAgeProvider;JILjava/lang/Object;)Lcom/apollographql/cache/normalized/RemovedFieldsAndRecords; + public static synthetic fun removeStaleFields-SxA4cEA$default (Lcom/apollographql/cache/normalized/SimpleApolloStore;Lcom/apollographql/cache/normalized/api/MaxAgeProvider;JILjava/lang/Object;)Lcom/apollographql/cache/normalized/RemovedFieldsAndRecords; public static synthetic fun removeStaleFields-SxA4cEA$default (Lcom/apollographql/cache/normalized/api/NormalizedCache;Lcom/apollographql/cache/normalized/api/MaxAgeProvider;JILjava/lang/Object;)Lcom/apollographql/cache/normalized/RemovedFieldsAndRecords; public static final fun removeUnreachableRecords (Lcom/apollographql/cache/normalized/ApolloStore;)Ljava/util/Set; + public static final fun removeUnreachableRecords (Lcom/apollographql/cache/normalized/SimpleApolloStore;)Ljava/util/Set; public static final fun removeUnreachableRecords (Lcom/apollographql/cache/normalized/api/NormalizedCache;)Ljava/util/Set; } @@ -190,6 +196,7 @@ public final class com/apollographql/cache/normalized/SimpleApolloStore { public final fun clearAll ()Z public final fun dispose ()V public final fun dump ()Ljava/util/Map; + public final fun getApolloStore ()Lcom/apollographql/cache/normalized/ApolloStore; public final fun getChangedKeys ()Lkotlinx/coroutines/flow/SharedFlow; public final fun normalize-Hljz6HE (Lcom/apollographql/apollo/api/Executable;Ljava/util/Map;Ljava/lang/String;)Ljava/util/Map; public static synthetic fun normalize-Hljz6HE$default (Lcom/apollographql/cache/normalized/SimpleApolloStore;Lcom/apollographql/apollo/api/Executable;Ljava/util/Map;Ljava/lang/String;ILjava/lang/Object;)Ljava/util/Map; diff --git a/normalized-cache/api/normalized-cache.klib.api b/normalized-cache/api/normalized-cache.klib.api index e119a291..7eddbe1a 100644 --- a/normalized-cache/api/normalized-cache.klib.api +++ b/normalized-cache/api/normalized-cache.klib.api @@ -473,6 +473,8 @@ final class com.apollographql.cache.normalized/RemovedFieldsAndRecords { // com. final class com.apollographql.cache.normalized/SimpleApolloStore { // com.apollographql.cache.normalized/SimpleApolloStore|null[0] constructor (com.apollographql.cache.normalized/ApolloStore, com.apollographql.apollo.api/CustomScalarAdapters) // com.apollographql.cache.normalized/SimpleApolloStore.|(com.apollographql.cache.normalized.ApolloStore;com.apollographql.apollo.api.CustomScalarAdapters){}[0] + final val apolloStore // com.apollographql.cache.normalized/SimpleApolloStore.apolloStore|{}apolloStore[0] + final fun (): com.apollographql.cache.normalized/ApolloStore // com.apollographql.cache.normalized/SimpleApolloStore.apolloStore.|(){}[0] final val changedKeys // com.apollographql.cache.normalized/SimpleApolloStore.changedKeys|{}changedKeys[0] final fun (): kotlinx.coroutines.flow/SharedFlow> // com.apollographql.cache.normalized/SimpleApolloStore.changedKeys.|(){}[0] @@ -612,6 +614,10 @@ final fun (com.apollographql.cache.normalized/ApolloStore).com.apollographql.cac final fun (com.apollographql.cache.normalized/ApolloStore).com.apollographql.cache.normalized/removeDanglingReferences(): com.apollographql.cache.normalized/RemovedFieldsAndRecords // com.apollographql.cache.normalized/removeDanglingReferences|removeDanglingReferences@com.apollographql.cache.normalized.ApolloStore(){}[0] final fun (com.apollographql.cache.normalized/ApolloStore).com.apollographql.cache.normalized/removeStaleFields(com.apollographql.cache.normalized.api/MaxAgeProvider, kotlin.time/Duration = ...): com.apollographql.cache.normalized/RemovedFieldsAndRecords // com.apollographql.cache.normalized/removeStaleFields|removeStaleFields@com.apollographql.cache.normalized.ApolloStore(com.apollographql.cache.normalized.api.MaxAgeProvider;kotlin.time.Duration){}[0] final fun (com.apollographql.cache.normalized/ApolloStore).com.apollographql.cache.normalized/removeUnreachableRecords(): kotlin.collections/Set // com.apollographql.cache.normalized/removeUnreachableRecords|removeUnreachableRecords@com.apollographql.cache.normalized.ApolloStore(){}[0] +final fun (com.apollographql.cache.normalized/SimpleApolloStore).com.apollographql.cache.normalized/garbageCollect(com.apollographql.cache.normalized.api/MaxAgeProvider, kotlin.time/Duration = ...): com.apollographql.cache.normalized/GarbageCollectResult // com.apollographql.cache.normalized/garbageCollect|garbageCollect@com.apollographql.cache.normalized.SimpleApolloStore(com.apollographql.cache.normalized.api.MaxAgeProvider;kotlin.time.Duration){}[0] +final fun (com.apollographql.cache.normalized/SimpleApolloStore).com.apollographql.cache.normalized/removeDanglingReferences(): com.apollographql.cache.normalized/RemovedFieldsAndRecords // com.apollographql.cache.normalized/removeDanglingReferences|removeDanglingReferences@com.apollographql.cache.normalized.SimpleApolloStore(){}[0] +final fun (com.apollographql.cache.normalized/SimpleApolloStore).com.apollographql.cache.normalized/removeStaleFields(com.apollographql.cache.normalized.api/MaxAgeProvider, kotlin.time/Duration = ...): com.apollographql.cache.normalized/RemovedFieldsAndRecords // com.apollographql.cache.normalized/removeStaleFields|removeStaleFields@com.apollographql.cache.normalized.SimpleApolloStore(com.apollographql.cache.normalized.api.MaxAgeProvider;kotlin.time.Duration){}[0] +final fun (com.apollographql.cache.normalized/SimpleApolloStore).com.apollographql.cache.normalized/removeUnreachableRecords(): kotlin.collections/Set // com.apollographql.cache.normalized/removeUnreachableRecords|removeUnreachableRecords@com.apollographql.cache.normalized.SimpleApolloStore(){}[0] final fun (kotlin.collections/Collection?).com.apollographql.cache.normalized.api/dependentKeys(): kotlin.collections/Set // com.apollographql.cache.normalized.api/dependentKeys|dependentKeys@kotlin.collections.Collection?(){}[0] final fun (kotlin.collections/Map).com.apollographql.cache.normalized/getReachableCacheKeys(): kotlin.collections/Set // com.apollographql.cache.normalized/getReachableCacheKeys|getReachableCacheKeys@kotlin.collections.Map(){}[0] final fun <#A: com.apollographql.apollo.api/Executable.Data> (#A).com.apollographql.cache.normalized.api/withErrors(com.apollographql.apollo.api/Executable<#A>, kotlin.collections/List?, com.apollographql.apollo.api/CustomScalarAdapters = ...): kotlin.collections/Map // com.apollographql.cache.normalized.api/withErrors|withErrors@0:0(com.apollographql.apollo.api.Executable<0:0>;kotlin.collections.List?;com.apollographql.apollo.api.CustomScalarAdapters){0§}[0] diff --git a/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/GarbageCollection.kt b/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/GarbageCollection.kt index ef670d0c..007ea1db 100644 --- a/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/GarbageCollection.kt +++ b/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/GarbageCollection.kt @@ -66,6 +66,11 @@ fun ApolloStore.removeUnreachableRecords(): Set { } } +/** + * @see removeUnreachableRecords + */ +fun SimpleApolloStore.removeUnreachableRecords() = apolloStore.removeUnreachableRecords() + /** * Remove all stale fields in the cache. * A field is stale if its received date is older than its max age (configurable via [maxAgeProvider]) or if its expiration date has @@ -186,6 +191,16 @@ fun ApolloStore.removeStaleFields( } } +/** + * @see removeStaleFields + */ +fun SimpleApolloStore.removeStaleFields( + maxAgeProvider: MaxAgeProvider, + maxStale: Duration = Duration.ZERO, +): RemovedFieldsAndRecords { + return apolloStore.removeStaleFields(maxAgeProvider, maxStale) +} + /** * Remove all dangling references in the cache. * A field is a dangling reference if its value (or, for lists, any of its values) is a reference to a record that does not exist. @@ -248,6 +263,13 @@ fun ApolloStore.removeDanglingReferences(): RemovedFieldsAndRecords { } } +/** + * @see removeDanglingReferences + */ +fun SimpleApolloStore.removeDanglingReferences(): RemovedFieldsAndRecords { + return apolloStore.removeDanglingReferences() +} + private fun RecordValue.isDanglingReference(allRecords: Map): Boolean { return when (this) { is CacheKey -> allRecords[this] == null @@ -317,6 +339,16 @@ fun ApolloStore.garbageCollect( } } +/** + * @see garbageCollect + */ +fun SimpleApolloStore.garbageCollect( + maxAgeProvider: MaxAgeProvider, + maxStale: Duration = Duration.ZERO, +): GarbageCollectResult { + return apolloStore.garbageCollect(maxAgeProvider, maxStale) +} + class RemovedFieldsAndRecords( val removedFields: Set, val removedRecords: Set, diff --git a/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/SimpleApolloStore.kt b/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/SimpleApolloStore.kt index 5721dd6f..5bf97431 100644 --- a/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/SimpleApolloStore.kt +++ b/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/SimpleApolloStore.kt @@ -20,7 +20,7 @@ import kotlin.reflect.KClass * A wrapper around [ApolloStore] that provides a simplified API for reading and writing data. */ class SimpleApolloStore( - private val apolloStore: ApolloStore, + val apolloStore: ApolloStore, private val customScalarAdapters: CustomScalarAdapters, ) { /** From 8be5630600fc0c0e13df6dc54034d9a8cf08e3f3 Mon Sep 17 00:00:00 2001 From: BoD Date: Thu, 24 Apr 2025 18:59:57 +0200 Subject: [PATCH 02/11] Heck, also make SimpleApolloStore.customScalarAdapters public --- normalized-cache/api/normalized-cache.api | 1 + normalized-cache/api/normalized-cache.klib.api | 2 ++ .../com/apollographql/cache/normalized/SimpleApolloStore.kt | 2 +- 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/normalized-cache/api/normalized-cache.api b/normalized-cache/api/normalized-cache.api index 6eac01dd..7eedf785 100644 --- a/normalized-cache/api/normalized-cache.api +++ b/normalized-cache/api/normalized-cache.api @@ -198,6 +198,7 @@ public final class com/apollographql/cache/normalized/SimpleApolloStore { public final fun dump ()Ljava/util/Map; public final fun getApolloStore ()Lcom/apollographql/cache/normalized/ApolloStore; public final fun getChangedKeys ()Lkotlinx/coroutines/flow/SharedFlow; + public final fun getCustomScalarAdapters ()Lcom/apollographql/apollo/api/CustomScalarAdapters; public final fun normalize-Hljz6HE (Lcom/apollographql/apollo/api/Executable;Ljava/util/Map;Ljava/lang/String;)Ljava/util/Map; public static synthetic fun normalize-Hljz6HE$default (Lcom/apollographql/cache/normalized/SimpleApolloStore;Lcom/apollographql/apollo/api/Executable;Ljava/util/Map;Ljava/lang/String;ILjava/lang/Object;)Ljava/util/Map; public final fun publish (Ljava/util/Set;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; diff --git a/normalized-cache/api/normalized-cache.klib.api b/normalized-cache/api/normalized-cache.klib.api index 7eddbe1a..f2d48851 100644 --- a/normalized-cache/api/normalized-cache.klib.api +++ b/normalized-cache/api/normalized-cache.klib.api @@ -477,6 +477,8 @@ final class com.apollographql.cache.normalized/SimpleApolloStore { // com.apollo final fun (): com.apollographql.cache.normalized/ApolloStore // com.apollographql.cache.normalized/SimpleApolloStore.apolloStore.|(){}[0] final val changedKeys // com.apollographql.cache.normalized/SimpleApolloStore.changedKeys|{}changedKeys[0] final fun (): kotlinx.coroutines.flow/SharedFlow> // com.apollographql.cache.normalized/SimpleApolloStore.changedKeys.|(){}[0] + final val customScalarAdapters // com.apollographql.cache.normalized/SimpleApolloStore.customScalarAdapters|{}customScalarAdapters[0] + final fun (): com.apollographql.apollo.api/CustomScalarAdapters // com.apollographql.cache.normalized/SimpleApolloStore.customScalarAdapters.|(){}[0] final fun <#A1: com.apollographql.apollo.api/Executable.Data> normalize(com.apollographql.apollo.api/Executable<#A1>, kotlin.collections/Map, com.apollographql.cache.normalized.api/CacheKey = ...): kotlin.collections/Map // com.apollographql.cache.normalized/SimpleApolloStore.normalize|normalize(com.apollographql.apollo.api.Executable<0:0>;kotlin.collections.Map;com.apollographql.cache.normalized.api.CacheKey){0§}[0] final fun <#A1: com.apollographql.apollo.api/Fragment.Data> readFragment(com.apollographql.apollo.api/Fragment<#A1>, com.apollographql.cache.normalized.api/CacheKey, com.apollographql.cache.normalized.api/CacheHeaders = ...): com.apollographql.cache.normalized/ApolloStore.ReadResult<#A1> // com.apollographql.cache.normalized/SimpleApolloStore.readFragment|readFragment(com.apollographql.apollo.api.Fragment<0:0>;com.apollographql.cache.normalized.api.CacheKey;com.apollographql.cache.normalized.api.CacheHeaders){0§}[0] diff --git a/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/SimpleApolloStore.kt b/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/SimpleApolloStore.kt index 5bf97431..b5d731f8 100644 --- a/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/SimpleApolloStore.kt +++ b/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/SimpleApolloStore.kt @@ -21,7 +21,7 @@ import kotlin.reflect.KClass */ class SimpleApolloStore( val apolloStore: ApolloStore, - private val customScalarAdapters: CustomScalarAdapters, + val customScalarAdapters: CustomScalarAdapters, ) { /** * @see ApolloStore.changedKeys From 44cd6f1d4b07033ff602a1f2544a10cdf41df962 Mon Sep 17 00:00:00 2001 From: BoD Date: Thu, 24 Apr 2025 20:05:05 +0200 Subject: [PATCH 03/11] Keep GarbageCollection extensions on SimpleApolloStore only --- normalized-cache/api/normalized-cache.api | 6 --- .../api/normalized-cache.klib.api | 4 -- .../cache/normalized/GarbageCollection.kt | 40 ++----------------- .../kotlin/DanglingReferencesTest.kt | 4 +- .../commonTest/kotlin/GarbageCollectTest.kt | 2 +- .../kotlin/ReachableCacheKeysTest.kt | 2 +- .../src/commonTest/kotlin/StaleFieldsTest.kt | 12 +++--- 7 files changed, 14 insertions(+), 56 deletions(-) diff --git a/normalized-cache/api/normalized-cache.api b/normalized-cache/api/normalized-cache.api index 7eedf785..8fb88eaf 100644 --- a/normalized-cache/api/normalized-cache.api +++ b/normalized-cache/api/normalized-cache.api @@ -120,23 +120,17 @@ public final class com/apollographql/cache/normalized/GarbageCollectResult { public final class com/apollographql/cache/normalized/GarbageCollectionKt { public static final fun allRecords (Lcom/apollographql/cache/normalized/api/NormalizedCache;)Ljava/util/Map; - public static final fun garbageCollect-SxA4cEA (Lcom/apollographql/cache/normalized/ApolloStore;Lcom/apollographql/cache/normalized/api/MaxAgeProvider;J)Lcom/apollographql/cache/normalized/GarbageCollectResult; public static final fun garbageCollect-SxA4cEA (Lcom/apollographql/cache/normalized/SimpleApolloStore;Lcom/apollographql/cache/normalized/api/MaxAgeProvider;J)Lcom/apollographql/cache/normalized/GarbageCollectResult; public static final fun garbageCollect-SxA4cEA (Lcom/apollographql/cache/normalized/api/NormalizedCache;Lcom/apollographql/cache/normalized/api/MaxAgeProvider;J)Lcom/apollographql/cache/normalized/GarbageCollectResult; - public static synthetic fun garbageCollect-SxA4cEA$default (Lcom/apollographql/cache/normalized/ApolloStore;Lcom/apollographql/cache/normalized/api/MaxAgeProvider;JILjava/lang/Object;)Lcom/apollographql/cache/normalized/GarbageCollectResult; public static synthetic fun garbageCollect-SxA4cEA$default (Lcom/apollographql/cache/normalized/SimpleApolloStore;Lcom/apollographql/cache/normalized/api/MaxAgeProvider;JILjava/lang/Object;)Lcom/apollographql/cache/normalized/GarbageCollectResult; public static synthetic fun garbageCollect-SxA4cEA$default (Lcom/apollographql/cache/normalized/api/NormalizedCache;Lcom/apollographql/cache/normalized/api/MaxAgeProvider;JILjava/lang/Object;)Lcom/apollographql/cache/normalized/GarbageCollectResult; public static final fun getReachableCacheKeys (Ljava/util/Map;)Ljava/util/Set; - public static final fun removeDanglingReferences (Lcom/apollographql/cache/normalized/ApolloStore;)Lcom/apollographql/cache/normalized/RemovedFieldsAndRecords; public static final fun removeDanglingReferences (Lcom/apollographql/cache/normalized/SimpleApolloStore;)Lcom/apollographql/cache/normalized/RemovedFieldsAndRecords; public static final fun removeDanglingReferences (Lcom/apollographql/cache/normalized/api/NormalizedCache;)Lcom/apollographql/cache/normalized/RemovedFieldsAndRecords; - public static final fun removeStaleFields-SxA4cEA (Lcom/apollographql/cache/normalized/ApolloStore;Lcom/apollographql/cache/normalized/api/MaxAgeProvider;J)Lcom/apollographql/cache/normalized/RemovedFieldsAndRecords; public static final fun removeStaleFields-SxA4cEA (Lcom/apollographql/cache/normalized/SimpleApolloStore;Lcom/apollographql/cache/normalized/api/MaxAgeProvider;J)Lcom/apollographql/cache/normalized/RemovedFieldsAndRecords; public static final fun removeStaleFields-SxA4cEA (Lcom/apollographql/cache/normalized/api/NormalizedCache;Lcom/apollographql/cache/normalized/api/MaxAgeProvider;J)Lcom/apollographql/cache/normalized/RemovedFieldsAndRecords; - public static synthetic fun removeStaleFields-SxA4cEA$default (Lcom/apollographql/cache/normalized/ApolloStore;Lcom/apollographql/cache/normalized/api/MaxAgeProvider;JILjava/lang/Object;)Lcom/apollographql/cache/normalized/RemovedFieldsAndRecords; public static synthetic fun removeStaleFields-SxA4cEA$default (Lcom/apollographql/cache/normalized/SimpleApolloStore;Lcom/apollographql/cache/normalized/api/MaxAgeProvider;JILjava/lang/Object;)Lcom/apollographql/cache/normalized/RemovedFieldsAndRecords; public static synthetic fun removeStaleFields-SxA4cEA$default (Lcom/apollographql/cache/normalized/api/NormalizedCache;Lcom/apollographql/cache/normalized/api/MaxAgeProvider;JILjava/lang/Object;)Lcom/apollographql/cache/normalized/RemovedFieldsAndRecords; - public static final fun removeUnreachableRecords (Lcom/apollographql/cache/normalized/ApolloStore;)Ljava/util/Set; public static final fun removeUnreachableRecords (Lcom/apollographql/cache/normalized/SimpleApolloStore;)Ljava/util/Set; public static final fun removeUnreachableRecords (Lcom/apollographql/cache/normalized/api/NormalizedCache;)Ljava/util/Set; } diff --git a/normalized-cache/api/normalized-cache.klib.api b/normalized-cache/api/normalized-cache.klib.api index f2d48851..36046f61 100644 --- a/normalized-cache/api/normalized-cache.klib.api +++ b/normalized-cache/api/normalized-cache.klib.api @@ -612,10 +612,6 @@ final fun (com.apollographql.cache.normalized.api/Record).com.apollographql.cach final fun (com.apollographql.cache.normalized.api/Record).com.apollographql.cache.normalized.api/receivedDate(kotlin/String): kotlin/Long? // com.apollographql.cache.normalized.api/receivedDate|receivedDate@com.apollographql.cache.normalized.api.Record(kotlin.String){}[0] final fun (com.apollographql.cache.normalized.api/Record).com.apollographql.cache.normalized.api/withDates(kotlin/String?, kotlin/String?): com.apollographql.cache.normalized.api/Record // com.apollographql.cache.normalized.api/withDates|withDates@com.apollographql.cache.normalized.api.Record(kotlin.String?;kotlin.String?){}[0] final fun (com.apollographql.cache.normalized.api/ResolverContext).com.apollographql.cache.normalized.api/getFieldKey(): kotlin/String // com.apollographql.cache.normalized.api/getFieldKey|getFieldKey@com.apollographql.cache.normalized.api.ResolverContext(){}[0] -final fun (com.apollographql.cache.normalized/ApolloStore).com.apollographql.cache.normalized/garbageCollect(com.apollographql.cache.normalized.api/MaxAgeProvider, kotlin.time/Duration = ...): com.apollographql.cache.normalized/GarbageCollectResult // com.apollographql.cache.normalized/garbageCollect|garbageCollect@com.apollographql.cache.normalized.ApolloStore(com.apollographql.cache.normalized.api.MaxAgeProvider;kotlin.time.Duration){}[0] -final fun (com.apollographql.cache.normalized/ApolloStore).com.apollographql.cache.normalized/removeDanglingReferences(): com.apollographql.cache.normalized/RemovedFieldsAndRecords // com.apollographql.cache.normalized/removeDanglingReferences|removeDanglingReferences@com.apollographql.cache.normalized.ApolloStore(){}[0] -final fun (com.apollographql.cache.normalized/ApolloStore).com.apollographql.cache.normalized/removeStaleFields(com.apollographql.cache.normalized.api/MaxAgeProvider, kotlin.time/Duration = ...): com.apollographql.cache.normalized/RemovedFieldsAndRecords // com.apollographql.cache.normalized/removeStaleFields|removeStaleFields@com.apollographql.cache.normalized.ApolloStore(com.apollographql.cache.normalized.api.MaxAgeProvider;kotlin.time.Duration){}[0] -final fun (com.apollographql.cache.normalized/ApolloStore).com.apollographql.cache.normalized/removeUnreachableRecords(): kotlin.collections/Set // com.apollographql.cache.normalized/removeUnreachableRecords|removeUnreachableRecords@com.apollographql.cache.normalized.ApolloStore(){}[0] final fun (com.apollographql.cache.normalized/SimpleApolloStore).com.apollographql.cache.normalized/garbageCollect(com.apollographql.cache.normalized.api/MaxAgeProvider, kotlin.time/Duration = ...): com.apollographql.cache.normalized/GarbageCollectResult // com.apollographql.cache.normalized/garbageCollect|garbageCollect@com.apollographql.cache.normalized.SimpleApolloStore(com.apollographql.cache.normalized.api.MaxAgeProvider;kotlin.time.Duration){}[0] final fun (com.apollographql.cache.normalized/SimpleApolloStore).com.apollographql.cache.normalized/removeDanglingReferences(): com.apollographql.cache.normalized/RemovedFieldsAndRecords // com.apollographql.cache.normalized/removeDanglingReferences|removeDanglingReferences@com.apollographql.cache.normalized.SimpleApolloStore(){}[0] final fun (com.apollographql.cache.normalized/SimpleApolloStore).com.apollographql.cache.normalized/removeStaleFields(com.apollographql.cache.normalized.api/MaxAgeProvider, kotlin.time/Duration = ...): com.apollographql.cache.normalized/RemovedFieldsAndRecords // com.apollographql.cache.normalized/removeStaleFields|removeStaleFields@com.apollographql.cache.normalized.SimpleApolloStore(com.apollographql.cache.normalized.api.MaxAgeProvider;kotlin.time.Duration){}[0] diff --git a/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/GarbageCollection.kt b/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/GarbageCollection.kt index 007ea1db..6934220e 100644 --- a/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/GarbageCollection.kt +++ b/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/GarbageCollection.kt @@ -60,17 +60,12 @@ private fun NormalizedCache.removeUnreachableRecords(allRecords: Map { +fun SimpleApolloStore.removeUnreachableRecords(): Set { return accessCache { cache -> cache.removeUnreachableRecords() } } -/** - * @see removeUnreachableRecords - */ -fun SimpleApolloStore.removeUnreachableRecords() = apolloStore.removeUnreachableRecords() - /** * Remove all stale fields in the cache. * A field is stale if its received date is older than its max age (configurable via [maxAgeProvider]) or if its expiration date has @@ -182,7 +177,7 @@ private fun NormalizedCache.removeStaleFields( * Remove all stale fields in the store. * @see removeStaleFields */ -fun ApolloStore.removeStaleFields( +fun SimpleApolloStore.removeStaleFields( maxAgeProvider: MaxAgeProvider, maxStale: Duration = Duration.ZERO, ): RemovedFieldsAndRecords { @@ -191,16 +186,6 @@ fun ApolloStore.removeStaleFields( } } -/** - * @see removeStaleFields - */ -fun SimpleApolloStore.removeStaleFields( - maxAgeProvider: MaxAgeProvider, - maxStale: Duration = Duration.ZERO, -): RemovedFieldsAndRecords { - return apolloStore.removeStaleFields(maxAgeProvider, maxStale) -} - /** * Remove all dangling references in the cache. * A field is a dangling reference if its value (or, for lists, any of its values) is a reference to a record that does not exist. @@ -257,19 +242,12 @@ private fun NormalizedCache.removeDanglingReferences(allRecords: MutableMap cache.removeDanglingReferences() } } -/** - * @see removeDanglingReferences - */ -fun SimpleApolloStore.removeDanglingReferences(): RemovedFieldsAndRecords { - return apolloStore.removeDanglingReferences() -} - private fun RecordValue.isDanglingReference(allRecords: Map): Boolean { return when (this) { is CacheKey -> allRecords[this] == null @@ -330,7 +308,7 @@ fun NormalizedCache.garbageCollect( * Perform garbage collection on the store. * @see garbageCollect */ -fun ApolloStore.garbageCollect( +fun SimpleApolloStore.garbageCollect( maxAgeProvider: MaxAgeProvider, maxStale: Duration = Duration.ZERO, ): GarbageCollectResult { @@ -339,16 +317,6 @@ fun ApolloStore.garbageCollect( } } -/** - * @see garbageCollect - */ -fun SimpleApolloStore.garbageCollect( - maxAgeProvider: MaxAgeProvider, - maxStale: Duration = Duration.ZERO, -): GarbageCollectResult { - return apolloStore.garbageCollect(maxAgeProvider, maxStale) -} - class RemovedFieldsAndRecords( val removedFields: Set, val removedRecords: Set, diff --git a/tests/garbage-collection/src/commonTest/kotlin/DanglingReferencesTest.kt b/tests/garbage-collection/src/commonTest/kotlin/DanglingReferencesTest.kt index c9cfed79..57e49ff6 100644 --- a/tests/garbage-collection/src/commonTest/kotlin/DanglingReferencesTest.kt +++ b/tests/garbage-collection/src/commonTest/kotlin/DanglingReferencesTest.kt @@ -52,7 +52,7 @@ class DanglingReferencesTest { // Remove User 1, now Repository 0.starGazers is a dangling reference store.remove(CacheKey("User:1"), cascade = false) - val removedFieldsAndRecords = store.removeDanglingReferences() + val removedFieldsAndRecords = apolloClient.store.removeDanglingReferences() assertEquals( setOf(CacheKey("Repository:0").fieldKey("starGazers")), removedFieldsAndRecords.removedFields @@ -96,7 +96,7 @@ class DanglingReferencesTest { // thus (QUERY_ROOT).metaProjects is a dangling reference // thus QUERY_ROOT is empty and removed store.remove(CacheKey("User:0"), cascade = false) - val removedFieldsAndRecords = store.removeDanglingReferences() + val removedFieldsAndRecords = apolloClient.store.removeDanglingReferences() assertEquals( setOf( CacheKey("metaProjects").append("0", "0", "type").fieldKey("owners"), diff --git a/tests/garbage-collection/src/commonTest/kotlin/GarbageCollectTest.kt b/tests/garbage-collection/src/commonTest/kotlin/GarbageCollectTest.kt index fe646c1a..5548e970 100644 --- a/tests/garbage-collection/src/commonTest/kotlin/GarbageCollectTest.kt +++ b/tests/garbage-collection/src/commonTest/kotlin/GarbageCollectTest.kt @@ -58,7 +58,7 @@ class GarbageCollectTest { Cache.maxAges, defaultMaxAge = 120.seconds, ) - val garbageCollectResult = store.garbageCollect(maxAgeProvider) + val garbageCollectResult = apolloClient.store.garbageCollect(maxAgeProvider) assertEquals( setOf( CacheKey("metaProjects").append("0", "0", "type").fieldKey("owners"), diff --git a/tests/garbage-collection/src/commonTest/kotlin/ReachableCacheKeysTest.kt b/tests/garbage-collection/src/commonTest/kotlin/ReachableCacheKeysTest.kt index 4c71f5e0..38ff205a 100644 --- a/tests/garbage-collection/src/commonTest/kotlin/ReachableCacheKeysTest.kt +++ b/tests/garbage-collection/src/commonTest/kotlin/ReachableCacheKeysTest.kt @@ -210,7 +210,7 @@ class ReachableCacheKeysTest { ) // Remove unreachable records, should remove Repositories 5, 6, and 500 - val removedKeys = store.removeUnreachableRecords() + val removedKeys = apolloClient.store.removeUnreachableRecords() assertEquals( setOf( CacheKey("QUERY_ROOT"), diff --git a/tests/garbage-collection/src/commonTest/kotlin/StaleFieldsTest.kt b/tests/garbage-collection/src/commonTest/kotlin/StaleFieldsTest.kt index 13f22189..3d1a5bc3 100644 --- a/tests/garbage-collection/src/commonTest/kotlin/StaleFieldsTest.kt +++ b/tests/garbage-collection/src/commonTest/kotlin/StaleFieldsTest.kt @@ -65,7 +65,7 @@ class StaleFieldsTest { Cache.maxAges, defaultMaxAge = 120.seconds, ) - var removedFieldsAndRecords = store.removeStaleFields(maxAgeProvider) + var removedFieldsAndRecords = apolloClient.store.removeStaleFields(maxAgeProvider) // Repository.stars has a max age of 60 seconds, so they should be removed / User has a max age of 90 seconds, so Repository.starGazers should be kept assertEquals( setOf( @@ -87,7 +87,7 @@ class StaleFieldsTest { .fetchPolicy(FetchPolicy.NetworkOnly) .cacheHeaders(receivedDate(currentTimeSeconds() - 90)) .execute() - removedFieldsAndRecords = store.removeStaleFields(maxAgeProvider) + removedFieldsAndRecords = apolloClient.store.removeStaleFields(maxAgeProvider) // Repository.stars and Repository.starGazers should be removed assertEquals( setOf( @@ -142,7 +142,7 @@ class StaleFieldsTest { Cache.maxAges, defaultMaxAge = 120.seconds, ) - var removedFieldsAndRecords = store.removeStaleFields(maxAgeProvider) + var removedFieldsAndRecords = apolloClient.store.removeStaleFields(maxAgeProvider) // Project.velocity has a max age of 60 seconds, so they should be removed / Project.isUrgent has a max age of 90 seconds, so they should be kept assertEquals( setOf( @@ -164,7 +164,7 @@ class StaleFieldsTest { .fetchPolicy(FetchPolicy.NetworkOnly) .cacheHeaders(receivedDate(currentTimeSeconds() - 90)) .execute() - removedFieldsAndRecords = store.removeStaleFields(maxAgeProvider) + removedFieldsAndRecords = apolloClient.store.removeStaleFields(maxAgeProvider) // Project.velocity and Project.isUrgent should be removed, their records being empty they should be removed assertEquals( setOf( @@ -216,7 +216,7 @@ class StaleFieldsTest { assertTrue(allRecords[CacheKey("Repository:1")]!!.fields.containsKey("stars")) assertTrue(allRecords[CacheKey("Repository:1")]!!.fields.containsKey("starGazers")) - var removedFieldsAndRecords = store.removeStaleFields(GlobalMaxAgeProvider(Duration.INFINITE)) + var removedFieldsAndRecords = apolloClient.store.removeStaleFields(GlobalMaxAgeProvider(Duration.INFINITE)) // Everything is stale assertEquals( setOf( @@ -259,7 +259,7 @@ class StaleFieldsTest { .cacheHeaders(expirationDate(currentTimeSeconds() - 60)) .execute() - removedFieldsAndRecords = store.removeStaleFields(GlobalMaxAgeProvider(Duration.INFINITE), maxStale = 70.seconds) + removedFieldsAndRecords = apolloClient.store.removeStaleFields(GlobalMaxAgeProvider(Duration.INFINITE), maxStale = 70.seconds) // Nothing is stale assertEquals( emptySet(), From b979c52d07493b6847ec78634ce9e4d3b9bcac17 Mon Sep 17 00:00:00 2001 From: BoD Date: Fri, 25 Apr 2025 11:48:19 +0200 Subject: [PATCH 04/11] Rename ApolloStore -> CacheManager --- Writerside/topics/migration-guide.md | 8 +- .../topics/pagination/pagination-manual.md | 4 +- .../topics/pagination/pagination-other.md | 2 +- .../pagination/pagination-relay-style.md | 2 +- .../cache/normalized/sql/TrimTest.kt | 14 +-- normalized-cache/api/normalized-cache.api | 114 +++++++++--------- .../api/normalized-cache.klib.api | 76 ++++++------ .../{ApolloStore.kt => CacheManager.kt} | 20 ++- .../cache/normalized/ClientCacheExtensions.kt | 20 +-- .../normalized/FetchPolicyInterceptors.kt | 2 +- .../cache/normalized/SimpleApolloStore.kt | 78 ++++++------ .../normalized/api/ApolloCacheHeaders.kt | 2 +- .../internal/ApolloCacheInterceptor.kt | 23 ++-- ...tApolloStore.kt => DefaultCacheManager.kt} | 10 +- .../normalized/internal/WatcherInterceptor.kt | 13 +- .../cache/normalized/MemoryCacheTest.kt | 4 +- .../pagination/pagination-support/README.md | 4 +- .../kotlin/test/DeferNormalizedCacheTest.kt | 13 +- .../kotlin/DanglingReferencesTest.kt | 37 +++--- .../commonTest/kotlin/GarbageCollectTest.kt | 17 +-- .../kotlin/ReachableCacheKeysTest.kt | 29 ++--- .../src/commonTest/kotlin/StaleFieldsTest.kt | 57 ++++----- .../src/commonTest/kotlin/MigrationTest.kt | 18 +-- .../src/commonTest/kotlin/test/BasicTest.kt | 10 +- .../src/commonTest/kotlin/test/StoreTest.kt | 22 ++-- .../src/commonTest/kotlin/test/BasicTest.kt | 10 +- .../src/commonTest/kotlin/test/StoreTest.kt | 22 ++-- .../src/commonTest/kotlin/test/BasicTest.kt | 10 +- .../src/commonTest/kotlin/test/StoreTest.kt | 22 ++-- .../kotlin/com/example/NormalizationTest.kt | 24 ++-- .../com/example/SqlNormalizationTest.kt | 6 +- .../src/commonTest/kotlin/BasicTest.kt | 10 +- .../src/commonTest/kotlin/CacheFlagsTest.kt | 14 +-- .../commonTest/kotlin/CacheResolverTest.kt | 8 +- .../src/commonTest/kotlin/FetchPolicyTest.kt | 32 ++--- .../kotlin/IdCacheKeyGeneratorTest.kt | 16 +-- .../src/commonTest/kotlin/JsonScalarTest.kt | 10 +- .../commonTest/kotlin/OptimisticCacheTest.kt | 46 +++---- .../src/commonTest/kotlin/OtherCacheTest.kt | 12 +- .../src/commonTest/kotlin/StoreTest.kt | 24 ++-- .../kotlin/WatcherErrorHandlingTest.kt | 10 +- .../src/commonTest/kotlin/WatcherTest.kt | 18 +-- .../kotlin/circular/CircularCacheReadTest.kt | 4 +- .../declarativecache/DeclarativeCacheTest.kt | 10 +- .../kotlin/MemoryCacheOnlyTest.kt | 14 +-- .../jvmTest/kotlin/CacheConcurrencyTest.kt | 10 +- .../kotlin/WriteToCacheAsynchronouslyTest.kt | 14 +-- .../kotlin/ConnectionPaginationTest.kt | 50 ++++---- .../ConnectionProgrammaticPaginationTest.kt | 42 +++---- .../ConnectionWithNodesPaginationTest.kt | 42 +++---- .../kotlin/CursorBasedPaginationTest.kt | 42 +++---- .../OffsetBasedWithArrayPaginationTest.kt | 42 +++---- ...fsetBasedWithPageAndInputPaginationTest.kt | 42 +++---- .../OffsetBasedWithPagePaginationTest.kt | 46 +++---- .../kotlin/test/CachePartialResultTest.kt | 15 +-- .../commonTest/kotlin/test/StoreErrorsTest.kt | 40 +++--- 56 files changed, 652 insertions(+), 654 deletions(-) rename normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/{ApolloStore.kt => CacheManager.kt} (95%) rename normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/internal/{DefaultApolloStore.kt => DefaultCacheManager.kt} (98%) diff --git a/Writerside/topics/migration-guide.md b/Writerside/topics/migration-guide.md index 9789cf64..c9a55405 100644 --- a/Writerside/topics/migration-guide.md +++ b/Writerside/topics/migration-guide.md @@ -106,18 +106,18 @@ store.writeOperation(operation, data).also { store.publish(it) } Previously, if you configured custom scalar adapters on your client, you had to pass them to the `ApolloStore` methods. -Now, `ApolloClient.apolloStore` returns a `SimpleApolloStore`, a wrapper around `ApolloStore` which passes the client's `CustomScalarAdapters` automatically. +Now, `ApolloClient.cacheManager` returns a `SimpleApolloStore`, a wrapper around `ApolloStore` which passes the client's `CustomScalarAdapters` automatically. ```kotlin // Before -client.apolloStore.writeOperation( +client.cacheManager.writeOperation( operation = operation, data = data, customScalarAdapters = client.customScalarAdapters ) // After -client.apolloStore.writeOperation( +client.cacheManager.writeOperation( operation = operation, data = data ) @@ -127,7 +127,7 @@ client.apolloStore.writeOperation( - `readFragment()` now returns a `ReadResult` (it previously returned a ``). This allows for surfacing metadata associated to the returned data, e.g. staleness. - Records are now rooted per operation type (`QUERY_ROOT`, `MUTATION_ROOT`, `SUBSCRIPTION_ROOT`), when previously these were all at the same level, which could cause conflicts. -- `ApolloClient.apolloStore` is deprecated in favor of `ApolloClient.store` for consistency. +- `ApolloClient.cacheManager` is deprecated in favor of `ApolloClient.store` for consistency. ## CacheResolver, CacheKeyResolver diff --git a/Writerside/topics/pagination/pagination-manual.md b/Writerside/topics/pagination/pagination-manual.md index 84e935e1..994c4c7e 100644 --- a/Writerside/topics/pagination/pagination-manual.md +++ b/Writerside/topics/pagination/pagination-manual.md @@ -23,8 +23,8 @@ suspend fun fetchAndMergePage(nextPage: Int) { ) // 4. Update the cache with the merged list - val keys = apolloClient.apolloStore.writeOperation(operation = listQuery, operationData = dataWithMergedList) - apolloClient.apolloStore.publish(keys) + val keys = apolloClient.cacheManager.writeOperation(operation = listQuery, operationData = dataWithMergedList) + apolloClient.cacheManager.publish(keys) } ``` diff --git a/Writerside/topics/pagination/pagination-other.md b/Writerside/topics/pagination/pagination-other.md index 4ac49f36..1420d703 100644 --- a/Writerside/topics/pagination/pagination-other.md +++ b/Writerside/topics/pagination/pagination-other.md @@ -59,7 +59,7 @@ object MyFieldMerger : FieldRecordMerger.FieldMerger { } } -val apolloStore = ApolloStore( +val cacheManager = ApolloStore( normalizedCacheFactory = cacheFactory, recordMerger = FieldRecordMerger(MyFieldMerger), // Configure the store with the custom merger ) diff --git a/Writerside/topics/pagination/pagination-relay-style.md b/Writerside/topics/pagination/pagination-relay-style.md index 55604c2c..d287e6fb 100644 --- a/Writerside/topics/pagination/pagination-relay-style.md +++ b/Writerside/topics/pagination/pagination-relay-style.md @@ -58,7 +58,7 @@ extend type Query @typePolicy(connectionFields: "usersConnection") In Kotlin, configure the `ApolloStore` like this, using the generated `Pagination` object: ```kotlin -val apolloStore = ApolloStore( +val cacheManager = ApolloStore( normalizedCacheFactory = cacheFactory, metadataGenerator = ConnectionMetadataGenerator(Pagination.connectionTypes), recordMerger = ConnectionRecordMerger diff --git a/normalized-cache-sqlite/src/commonTest/kotlin/com/apollographql/cache/normalized/sql/TrimTest.kt b/normalized-cache-sqlite/src/commonTest/kotlin/com/apollographql/cache/normalized/sql/TrimTest.kt index c224136a..23cdc865 100644 --- a/normalized-cache-sqlite/src/commonTest/kotlin/com/apollographql/cache/normalized/sql/TrimTest.kt +++ b/normalized-cache-sqlite/src/commonTest/kotlin/com/apollographql/cache/normalized/sql/TrimTest.kt @@ -1,6 +1,6 @@ package com.apollographql.cache.normalized.sql -import com.apollographql.cache.normalized.ApolloStore +import com.apollographql.cache.normalized.CacheManager import com.apollographql.cache.normalized.api.CacheHeaders import com.apollographql.cache.normalized.api.CacheKey import com.apollographql.cache.normalized.api.DefaultRecordMerger @@ -13,7 +13,7 @@ import kotlin.test.assertNull class TrimTest { @Test fun trimTest() { - val apolloStore = ApolloStore(SqlNormalizedCacheFactory()).also { it.clearAll() } + val cacheManager = CacheManager(SqlNormalizedCacheFactory()).also { it.clearAll() } val largeString = "".padStart(1024, '?') @@ -23,7 +23,7 @@ class TrimTest { mutationId = null, metadata = emptyMap() ) - apolloStore.accessCache { it.merge(oldRecord, CacheHeaders.NONE, recordMerger = DefaultRecordMerger) } + cacheManager.accessCache { it.merge(oldRecord, CacheHeaders.NONE, recordMerger = DefaultRecordMerger) } val newRecords = 0.until(2 * 1024).map { Record( @@ -33,16 +33,16 @@ class TrimTest { metadata = emptyMap() ).withDates(receivedDate = it.toString(), expirationDate = null) } - apolloStore.accessCache { it.merge(newRecords, CacheHeaders.NONE, recordMerger = DefaultRecordMerger) } + cacheManager.accessCache { it.merge(newRecords, CacheHeaders.NONE, recordMerger = DefaultRecordMerger) } - val sizeBeforeTrim = apolloStore.trim(-1, 0.1f) + val sizeBeforeTrim = cacheManager.trim(-1, 0.1f) assertEquals(8515584, sizeBeforeTrim) // Trim the cache by 10% - val sizeAfterTrim = apolloStore.trim(8515584, 0.1f) + val sizeAfterTrim = cacheManager.trim(8515584, 0.1f) assertEquals(7667712, sizeAfterTrim) // The oldest key must have been removed - assertNull(apolloStore.accessCache { it.loadRecord(CacheKey("old"), CacheHeaders.NONE) }) + assertNull(cacheManager.accessCache { it.loadRecord(CacheKey("old"), CacheHeaders.NONE) }) } } diff --git a/normalized-cache/api/normalized-cache.api b/normalized-cache/api/normalized-cache.api index 8fb88eaf..a21037c6 100644 --- a/normalized-cache/api/normalized-cache.api +++ b/normalized-cache/api/normalized-cache.api @@ -1,54 +1,3 @@ -public abstract interface class com/apollographql/cache/normalized/ApolloStore { - public static final field Companion Lcom/apollographql/cache/normalized/ApolloStore$Companion; - public abstract fun accessCache (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public abstract fun clearAll ()Z - public abstract fun dispose ()V - public abstract fun dump ()Ljava/util/Map; - public abstract fun getChangedKeys ()Lkotlinx/coroutines/flow/SharedFlow; - public abstract fun normalize-niOPdRo (Lcom/apollographql/apollo/api/Executable;Ljava/util/Map;Ljava/lang/String;Lcom/apollographql/apollo/api/CustomScalarAdapters;)Ljava/util/Map; - public abstract fun publish (Ljava/util/Set;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun readFragment-dEpVOtE (Lcom/apollographql/apollo/api/Fragment;Ljava/lang/String;Lcom/apollographql/apollo/api/CustomScalarAdapters;Lcom/apollographql/cache/normalized/api/CacheHeaders;)Lcom/apollographql/cache/normalized/ApolloStore$ReadResult; - public abstract fun readOperation (Lcom/apollographql/apollo/api/Operation;Lcom/apollographql/apollo/api/CustomScalarAdapters;Lcom/apollographql/cache/normalized/api/CacheHeaders;)Lcom/apollographql/apollo/api/ApolloResponse; - public abstract fun remove (Ljava/util/List;Z)I - public abstract fun remove-eNSUWrY (Ljava/lang/String;Z)Z - public abstract fun rollbackOptimisticUpdates (Ljava/util/UUID;)Ljava/util/Set; - public abstract fun trim (JF)J - public abstract fun writeFragment-1qdIjGk (Lcom/apollographql/apollo/api/Fragment;Ljava/lang/String;Lcom/apollographql/apollo/api/Fragment$Data;Lcom/apollographql/apollo/api/CustomScalarAdapters;Lcom/apollographql/cache/normalized/api/CacheHeaders;)Ljava/util/Set; - public abstract fun writeOperation (Lcom/apollographql/apollo/api/Operation;Lcom/apollographql/apollo/api/Operation$Data;Ljava/util/List;Lcom/apollographql/apollo/api/CustomScalarAdapters;Lcom/apollographql/cache/normalized/api/CacheHeaders;)Ljava/util/Set; - public abstract fun writeOperation (Lcom/apollographql/apollo/api/Operation;Ljava/util/Map;Lcom/apollographql/apollo/api/CustomScalarAdapters;Lcom/apollographql/cache/normalized/api/CacheHeaders;)Ljava/util/Set; - public abstract fun writeOptimisticUpdates (Lcom/apollographql/apollo/api/Operation;Lcom/apollographql/apollo/api/Operation$Data;Ljava/util/UUID;Lcom/apollographql/apollo/api/CustomScalarAdapters;)Ljava/util/Set; - public abstract fun writeOptimisticUpdates-1qdIjGk (Lcom/apollographql/apollo/api/Fragment;Ljava/lang/String;Lcom/apollographql/apollo/api/Fragment$Data;Ljava/util/UUID;Lcom/apollographql/apollo/api/CustomScalarAdapters;)Ljava/util/Set; -} - -public final class com/apollographql/cache/normalized/ApolloStore$Companion { - public final fun getALL_KEYS ()Lkotlin/collections/AbstractSet; -} - -public final class com/apollographql/cache/normalized/ApolloStore$DefaultImpls { - public static synthetic fun normalize-niOPdRo$default (Lcom/apollographql/cache/normalized/ApolloStore;Lcom/apollographql/apollo/api/Executable;Ljava/util/Map;Ljava/lang/String;Lcom/apollographql/apollo/api/CustomScalarAdapters;ILjava/lang/Object;)Ljava/util/Map; - public static synthetic fun readFragment-dEpVOtE$default (Lcom/apollographql/cache/normalized/ApolloStore;Lcom/apollographql/apollo/api/Fragment;Ljava/lang/String;Lcom/apollographql/apollo/api/CustomScalarAdapters;Lcom/apollographql/cache/normalized/api/CacheHeaders;ILjava/lang/Object;)Lcom/apollographql/cache/normalized/ApolloStore$ReadResult; - public static synthetic fun readOperation$default (Lcom/apollographql/cache/normalized/ApolloStore;Lcom/apollographql/apollo/api/Operation;Lcom/apollographql/apollo/api/CustomScalarAdapters;Lcom/apollographql/cache/normalized/api/CacheHeaders;ILjava/lang/Object;)Lcom/apollographql/apollo/api/ApolloResponse; - public static synthetic fun remove$default (Lcom/apollographql/cache/normalized/ApolloStore;Ljava/util/List;ZILjava/lang/Object;)I - public static synthetic fun remove-eNSUWrY$default (Lcom/apollographql/cache/normalized/ApolloStore;Ljava/lang/String;ZILjava/lang/Object;)Z - public static synthetic fun trim$default (Lcom/apollographql/cache/normalized/ApolloStore;JFILjava/lang/Object;)J - public static synthetic fun writeFragment-1qdIjGk$default (Lcom/apollographql/cache/normalized/ApolloStore;Lcom/apollographql/apollo/api/Fragment;Ljava/lang/String;Lcom/apollographql/apollo/api/Fragment$Data;Lcom/apollographql/apollo/api/CustomScalarAdapters;Lcom/apollographql/cache/normalized/api/CacheHeaders;ILjava/lang/Object;)Ljava/util/Set; - public static synthetic fun writeOperation$default (Lcom/apollographql/cache/normalized/ApolloStore;Lcom/apollographql/apollo/api/Operation;Lcom/apollographql/apollo/api/Operation$Data;Ljava/util/List;Lcom/apollographql/apollo/api/CustomScalarAdapters;Lcom/apollographql/cache/normalized/api/CacheHeaders;ILjava/lang/Object;)Ljava/util/Set; - public static synthetic fun writeOperation$default (Lcom/apollographql/cache/normalized/ApolloStore;Lcom/apollographql/apollo/api/Operation;Ljava/util/Map;Lcom/apollographql/apollo/api/CustomScalarAdapters;Lcom/apollographql/cache/normalized/api/CacheHeaders;ILjava/lang/Object;)Ljava/util/Set; - public static synthetic fun writeOptimisticUpdates$default (Lcom/apollographql/cache/normalized/ApolloStore;Lcom/apollographql/apollo/api/Operation;Lcom/apollographql/apollo/api/Operation$Data;Ljava/util/UUID;Lcom/apollographql/apollo/api/CustomScalarAdapters;ILjava/lang/Object;)Ljava/util/Set; - public static synthetic fun writeOptimisticUpdates-1qdIjGk$default (Lcom/apollographql/cache/normalized/ApolloStore;Lcom/apollographql/apollo/api/Fragment;Ljava/lang/String;Lcom/apollographql/apollo/api/Fragment$Data;Ljava/util/UUID;Lcom/apollographql/apollo/api/CustomScalarAdapters;ILjava/lang/Object;)Ljava/util/Set; -} - -public final class com/apollographql/cache/normalized/ApolloStore$ReadResult { - public fun (Lcom/apollographql/apollo/api/Executable$Data;Lcom/apollographql/cache/normalized/api/CacheHeaders;)V - public final fun getCacheHeaders ()Lcom/apollographql/cache/normalized/api/CacheHeaders; - public final fun getData ()Lcom/apollographql/apollo/api/Executable$Data; -} - -public final class com/apollographql/cache/normalized/ApolloStoreKt { - public static final fun ApolloStore (Lcom/apollographql/cache/normalized/api/NormalizedCacheFactory;Lcom/apollographql/cache/normalized/api/CacheKeyGenerator;Lcom/apollographql/cache/normalized/api/MetadataGenerator;Lcom/apollographql/cache/normalized/api/CacheResolver;Lcom/apollographql/cache/normalized/api/RecordMerger;Lcom/apollographql/cache/normalized/api/FieldKeyGenerator;Lcom/apollographql/cache/normalized/api/EmbeddedFieldsProvider;Lcom/apollographql/cache/normalized/api/MaxAgeProvider;)Lcom/apollographql/cache/normalized/ApolloStore; - public static synthetic fun ApolloStore$default (Lcom/apollographql/cache/normalized/api/NormalizedCacheFactory;Lcom/apollographql/cache/normalized/api/CacheKeyGenerator;Lcom/apollographql/cache/normalized/api/MetadataGenerator;Lcom/apollographql/cache/normalized/api/CacheResolver;Lcom/apollographql/cache/normalized/api/RecordMerger;Lcom/apollographql/cache/normalized/api/FieldKeyGenerator;Lcom/apollographql/cache/normalized/api/EmbeddedFieldsProvider;Lcom/apollographql/cache/normalized/api/MaxAgeProvider;ILjava/lang/Object;)Lcom/apollographql/cache/normalized/ApolloStore; -} - public final class com/apollographql/cache/normalized/CacheInfo : com/apollographql/apollo/api/ExecutionContext$Element { public static final field Key Lcom/apollographql/cache/normalized/CacheInfo$Key; public synthetic fun (JJJJZZLcom/apollographql/apollo/exception/CacheMissException;Lcom/apollographql/apollo/exception/ApolloException;ZLkotlin/jvm/internal/DefaultConstructorMarker;)V @@ -82,6 +31,57 @@ public final class com/apollographql/cache/normalized/CacheInfo$Builder { public final class com/apollographql/cache/normalized/CacheInfo$Key : com/apollographql/apollo/api/ExecutionContext$Key { } +public abstract interface class com/apollographql/cache/normalized/CacheManager { + public static final field Companion Lcom/apollographql/cache/normalized/CacheManager$Companion; + public abstract fun accessCache (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public abstract fun clearAll ()Z + public abstract fun dispose ()V + public abstract fun dump ()Ljava/util/Map; + public abstract fun getChangedKeys ()Lkotlinx/coroutines/flow/SharedFlow; + public abstract fun normalize-niOPdRo (Lcom/apollographql/apollo/api/Executable;Ljava/util/Map;Ljava/lang/String;Lcom/apollographql/apollo/api/CustomScalarAdapters;)Ljava/util/Map; + public abstract fun publish (Ljava/util/Set;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public abstract fun readFragment-dEpVOtE (Lcom/apollographql/apollo/api/Fragment;Ljava/lang/String;Lcom/apollographql/apollo/api/CustomScalarAdapters;Lcom/apollographql/cache/normalized/api/CacheHeaders;)Lcom/apollographql/cache/normalized/CacheManager$ReadResult; + public abstract fun readOperation (Lcom/apollographql/apollo/api/Operation;Lcom/apollographql/apollo/api/CustomScalarAdapters;Lcom/apollographql/cache/normalized/api/CacheHeaders;)Lcom/apollographql/apollo/api/ApolloResponse; + public abstract fun remove (Ljava/util/List;Z)I + public abstract fun remove-eNSUWrY (Ljava/lang/String;Z)Z + public abstract fun rollbackOptimisticUpdates (Ljava/util/UUID;)Ljava/util/Set; + public abstract fun trim (JF)J + public abstract fun writeFragment-1qdIjGk (Lcom/apollographql/apollo/api/Fragment;Ljava/lang/String;Lcom/apollographql/apollo/api/Fragment$Data;Lcom/apollographql/apollo/api/CustomScalarAdapters;Lcom/apollographql/cache/normalized/api/CacheHeaders;)Ljava/util/Set; + public abstract fun writeOperation (Lcom/apollographql/apollo/api/Operation;Lcom/apollographql/apollo/api/Operation$Data;Ljava/util/List;Lcom/apollographql/apollo/api/CustomScalarAdapters;Lcom/apollographql/cache/normalized/api/CacheHeaders;)Ljava/util/Set; + public abstract fun writeOperation (Lcom/apollographql/apollo/api/Operation;Ljava/util/Map;Lcom/apollographql/apollo/api/CustomScalarAdapters;Lcom/apollographql/cache/normalized/api/CacheHeaders;)Ljava/util/Set; + public abstract fun writeOptimisticUpdates (Lcom/apollographql/apollo/api/Operation;Lcom/apollographql/apollo/api/Operation$Data;Ljava/util/UUID;Lcom/apollographql/apollo/api/CustomScalarAdapters;)Ljava/util/Set; + public abstract fun writeOptimisticUpdates-1qdIjGk (Lcom/apollographql/apollo/api/Fragment;Ljava/lang/String;Lcom/apollographql/apollo/api/Fragment$Data;Ljava/util/UUID;Lcom/apollographql/apollo/api/CustomScalarAdapters;)Ljava/util/Set; +} + +public final class com/apollographql/cache/normalized/CacheManager$Companion { + public final fun getALL_KEYS ()Lkotlin/collections/AbstractSet; +} + +public final class com/apollographql/cache/normalized/CacheManager$DefaultImpls { + public static synthetic fun normalize-niOPdRo$default (Lcom/apollographql/cache/normalized/CacheManager;Lcom/apollographql/apollo/api/Executable;Ljava/util/Map;Ljava/lang/String;Lcom/apollographql/apollo/api/CustomScalarAdapters;ILjava/lang/Object;)Ljava/util/Map; + public static synthetic fun readFragment-dEpVOtE$default (Lcom/apollographql/cache/normalized/CacheManager;Lcom/apollographql/apollo/api/Fragment;Ljava/lang/String;Lcom/apollographql/apollo/api/CustomScalarAdapters;Lcom/apollographql/cache/normalized/api/CacheHeaders;ILjava/lang/Object;)Lcom/apollographql/cache/normalized/CacheManager$ReadResult; + public static synthetic fun readOperation$default (Lcom/apollographql/cache/normalized/CacheManager;Lcom/apollographql/apollo/api/Operation;Lcom/apollographql/apollo/api/CustomScalarAdapters;Lcom/apollographql/cache/normalized/api/CacheHeaders;ILjava/lang/Object;)Lcom/apollographql/apollo/api/ApolloResponse; + public static synthetic fun remove$default (Lcom/apollographql/cache/normalized/CacheManager;Ljava/util/List;ZILjava/lang/Object;)I + public static synthetic fun remove-eNSUWrY$default (Lcom/apollographql/cache/normalized/CacheManager;Ljava/lang/String;ZILjava/lang/Object;)Z + public static synthetic fun trim$default (Lcom/apollographql/cache/normalized/CacheManager;JFILjava/lang/Object;)J + public static synthetic fun writeFragment-1qdIjGk$default (Lcom/apollographql/cache/normalized/CacheManager;Lcom/apollographql/apollo/api/Fragment;Ljava/lang/String;Lcom/apollographql/apollo/api/Fragment$Data;Lcom/apollographql/apollo/api/CustomScalarAdapters;Lcom/apollographql/cache/normalized/api/CacheHeaders;ILjava/lang/Object;)Ljava/util/Set; + public static synthetic fun writeOperation$default (Lcom/apollographql/cache/normalized/CacheManager;Lcom/apollographql/apollo/api/Operation;Lcom/apollographql/apollo/api/Operation$Data;Ljava/util/List;Lcom/apollographql/apollo/api/CustomScalarAdapters;Lcom/apollographql/cache/normalized/api/CacheHeaders;ILjava/lang/Object;)Ljava/util/Set; + public static synthetic fun writeOperation$default (Lcom/apollographql/cache/normalized/CacheManager;Lcom/apollographql/apollo/api/Operation;Ljava/util/Map;Lcom/apollographql/apollo/api/CustomScalarAdapters;Lcom/apollographql/cache/normalized/api/CacheHeaders;ILjava/lang/Object;)Ljava/util/Set; + public static synthetic fun writeOptimisticUpdates$default (Lcom/apollographql/cache/normalized/CacheManager;Lcom/apollographql/apollo/api/Operation;Lcom/apollographql/apollo/api/Operation$Data;Ljava/util/UUID;Lcom/apollographql/apollo/api/CustomScalarAdapters;ILjava/lang/Object;)Ljava/util/Set; + public static synthetic fun writeOptimisticUpdates-1qdIjGk$default (Lcom/apollographql/cache/normalized/CacheManager;Lcom/apollographql/apollo/api/Fragment;Ljava/lang/String;Lcom/apollographql/apollo/api/Fragment$Data;Ljava/util/UUID;Lcom/apollographql/apollo/api/CustomScalarAdapters;ILjava/lang/Object;)Ljava/util/Set; +} + +public final class com/apollographql/cache/normalized/CacheManager$ReadResult { + public fun (Lcom/apollographql/apollo/api/Executable$Data;Lcom/apollographql/cache/normalized/api/CacheHeaders;)V + public final fun getCacheHeaders ()Lcom/apollographql/cache/normalized/api/CacheHeaders; + public final fun getData ()Lcom/apollographql/apollo/api/Executable$Data; +} + +public final class com/apollographql/cache/normalized/CacheManagerKt { + public static final fun CacheManager (Lcom/apollographql/cache/normalized/api/NormalizedCacheFactory;Lcom/apollographql/cache/normalized/api/CacheKeyGenerator;Lcom/apollographql/cache/normalized/api/MetadataGenerator;Lcom/apollographql/cache/normalized/api/CacheResolver;Lcom/apollographql/cache/normalized/api/RecordMerger;Lcom/apollographql/cache/normalized/api/FieldKeyGenerator;Lcom/apollographql/cache/normalized/api/EmbeddedFieldsProvider;Lcom/apollographql/cache/normalized/api/MaxAgeProvider;)Lcom/apollographql/cache/normalized/CacheManager; + public static synthetic fun CacheManager$default (Lcom/apollographql/cache/normalized/api/NormalizedCacheFactory;Lcom/apollographql/cache/normalized/api/CacheKeyGenerator;Lcom/apollographql/cache/normalized/api/MetadataGenerator;Lcom/apollographql/cache/normalized/api/CacheResolver;Lcom/apollographql/cache/normalized/api/RecordMerger;Lcom/apollographql/cache/normalized/api/FieldKeyGenerator;Lcom/apollographql/cache/normalized/api/EmbeddedFieldsProvider;Lcom/apollographql/cache/normalized/api/MaxAgeProvider;ILjava/lang/Object;)Lcom/apollographql/cache/normalized/CacheManager; +} + public final class com/apollographql/cache/normalized/CacheMissLoggingInterceptor : com/apollographql/apollo/interceptor/ApolloInterceptor { public fun (Lkotlin/jvm/functions/Function1;)V public fun intercept (Lcom/apollographql/apollo/api/ApolloRequest;Lcom/apollographql/apollo/interceptor/ApolloInterceptorChain;)Lkotlinx/coroutines/flow/Flow; @@ -141,6 +141,8 @@ public final class com/apollographql/cache/normalized/NormalizedCache { public static final fun addCacheHeader (Lcom/apollographql/apollo/api/MutableExecutionOptions;Ljava/lang/String;Ljava/lang/String;)Ljava/lang/Object; public static final fun cacheHeaders (Lcom/apollographql/apollo/api/ApolloResponse$Builder;Lcom/apollographql/cache/normalized/api/CacheHeaders;)Lcom/apollographql/apollo/api/ApolloResponse$Builder; public static final fun cacheHeaders (Lcom/apollographql/apollo/api/MutableExecutionOptions;Lcom/apollographql/cache/normalized/api/CacheHeaders;)Ljava/lang/Object; + public static final fun cacheManager (Lcom/apollographql/apollo/ApolloClient$Builder;Lcom/apollographql/cache/normalized/CacheManager;Z)Lcom/apollographql/apollo/ApolloClient$Builder; + public static synthetic fun cacheManager$default (Lcom/apollographql/apollo/ApolloClient$Builder;Lcom/apollographql/cache/normalized/CacheManager;ZILjava/lang/Object;)Lcom/apollographql/apollo/ApolloClient$Builder; public static final fun configureApolloClientBuilder2 (Lcom/apollographql/apollo/ApolloClient$Builder;Lcom/apollographql/cache/normalized/api/NormalizedCacheFactory;)Lcom/apollographql/apollo/ApolloClient$Builder; public static final fun configureApolloClientBuilder2 (Lcom/apollographql/apollo/ApolloClient$Builder;Lcom/apollographql/cache/normalized/api/NormalizedCacheFactory;Lcom/apollographql/cache/normalized/api/CacheKeyGenerator;)Lcom/apollographql/apollo/ApolloClient$Builder; public static final fun configureApolloClientBuilder2 (Lcom/apollographql/apollo/ApolloClient$Builder;Lcom/apollographql/cache/normalized/api/NormalizedCacheFactory;Lcom/apollographql/cache/normalized/api/CacheKeyGenerator;Lcom/apollographql/cache/normalized/api/MetadataGenerator;)Lcom/apollographql/apollo/ApolloClient$Builder; @@ -168,8 +170,6 @@ public final class com/apollographql/cache/normalized/NormalizedCache { public static final fun optimisticUpdates (Lcom/apollographql/apollo/api/ApolloRequest$Builder;Lcom/apollographql/apollo/api/Mutation$Data;)Lcom/apollographql/apollo/api/ApolloRequest$Builder; public static final fun refetchPolicy (Lcom/apollographql/apollo/api/MutableExecutionOptions;Lcom/apollographql/cache/normalized/FetchPolicy;)Ljava/lang/Object; public static final fun refetchPolicyInterceptor (Lcom/apollographql/apollo/api/MutableExecutionOptions;Lcom/apollographql/apollo/interceptor/ApolloInterceptor;)Ljava/lang/Object; - public static final fun store (Lcom/apollographql/apollo/ApolloClient$Builder;Lcom/apollographql/cache/normalized/ApolloStore;Z)Lcom/apollographql/apollo/ApolloClient$Builder; - public static synthetic fun store$default (Lcom/apollographql/apollo/ApolloClient$Builder;Lcom/apollographql/cache/normalized/ApolloStore;ZILjava/lang/Object;)Lcom/apollographql/apollo/ApolloClient$Builder; public static final fun storeExpirationDate (Lcom/apollographql/apollo/api/MutableExecutionOptions;Z)Ljava/lang/Object; public static final fun storePartialResponses (Lcom/apollographql/apollo/api/MutableExecutionOptions;Z)Ljava/lang/Void; public static final fun storeReceivedDate (Lcom/apollographql/apollo/api/MutableExecutionOptions;Z)Ljava/lang/Object; @@ -185,19 +185,19 @@ public final class com/apollographql/cache/normalized/RemovedFieldsAndRecords { } public final class com/apollographql/cache/normalized/SimpleApolloStore { - public fun (Lcom/apollographql/cache/normalized/ApolloStore;Lcom/apollographql/apollo/api/CustomScalarAdapters;)V + public fun (Lcom/apollographql/cache/normalized/CacheManager;Lcom/apollographql/apollo/api/CustomScalarAdapters;)V public final fun accessCache (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public final fun clearAll ()Z public final fun dispose ()V public final fun dump ()Ljava/util/Map; - public final fun getApolloStore ()Lcom/apollographql/cache/normalized/ApolloStore; + public final fun getCacheManager ()Lcom/apollographql/cache/normalized/CacheManager; public final fun getChangedKeys ()Lkotlinx/coroutines/flow/SharedFlow; public final fun getCustomScalarAdapters ()Lcom/apollographql/apollo/api/CustomScalarAdapters; public final fun normalize-Hljz6HE (Lcom/apollographql/apollo/api/Executable;Ljava/util/Map;Ljava/lang/String;)Ljava/util/Map; public static synthetic fun normalize-Hljz6HE$default (Lcom/apollographql/cache/normalized/SimpleApolloStore;Lcom/apollographql/apollo/api/Executable;Ljava/util/Map;Ljava/lang/String;ILjava/lang/Object;)Ljava/util/Map; public final fun publish (Ljava/util/Set;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public final fun readFragment-0aEo43o (Lcom/apollographql/apollo/api/Fragment;Ljava/lang/String;Lcom/apollographql/cache/normalized/api/CacheHeaders;)Lcom/apollographql/cache/normalized/ApolloStore$ReadResult; - public static synthetic fun readFragment-0aEo43o$default (Lcom/apollographql/cache/normalized/SimpleApolloStore;Lcom/apollographql/apollo/api/Fragment;Ljava/lang/String;Lcom/apollographql/cache/normalized/api/CacheHeaders;ILjava/lang/Object;)Lcom/apollographql/cache/normalized/ApolloStore$ReadResult; + public final fun readFragment-0aEo43o (Lcom/apollographql/apollo/api/Fragment;Ljava/lang/String;Lcom/apollographql/cache/normalized/api/CacheHeaders;)Lcom/apollographql/cache/normalized/CacheManager$ReadResult; + public static synthetic fun readFragment-0aEo43o$default (Lcom/apollographql/cache/normalized/SimpleApolloStore;Lcom/apollographql/apollo/api/Fragment;Ljava/lang/String;Lcom/apollographql/cache/normalized/api/CacheHeaders;ILjava/lang/Object;)Lcom/apollographql/cache/normalized/CacheManager$ReadResult; public final fun readOperation (Lcom/apollographql/apollo/api/Operation;Lcom/apollographql/cache/normalized/api/CacheHeaders;)Lcom/apollographql/apollo/api/ApolloResponse; public static synthetic fun readOperation$default (Lcom/apollographql/cache/normalized/SimpleApolloStore;Lcom/apollographql/apollo/api/Operation;Lcom/apollographql/cache/normalized/api/CacheHeaders;ILjava/lang/Object;)Lcom/apollographql/apollo/api/ApolloResponse; public final fun remove (Ljava/util/List;Z)I diff --git a/normalized-cache/api/normalized-cache.klib.api b/normalized-cache/api/normalized-cache.klib.api index 36046f61..eb69b497 100644 --- a/normalized-cache/api/normalized-cache.klib.api +++ b/normalized-cache/api/normalized-cache.klib.api @@ -76,40 +76,40 @@ abstract interface com.apollographql.cache.normalized.api/RecordMerger { // com. abstract fun merge(com.apollographql.cache.normalized.api/RecordMergerContext): kotlin/Pair> // com.apollographql.cache.normalized.api/RecordMerger.merge|merge(com.apollographql.cache.normalized.api.RecordMergerContext){}[0] } -abstract interface com.apollographql.cache.normalized/ApolloStore { // com.apollographql.cache.normalized/ApolloStore|null[0] - abstract val changedKeys // com.apollographql.cache.normalized/ApolloStore.changedKeys|{}changedKeys[0] - abstract fun (): kotlinx.coroutines.flow/SharedFlow> // com.apollographql.cache.normalized/ApolloStore.changedKeys.|(){}[0] - - abstract fun <#A1: com.apollographql.apollo.api/Executable.Data> normalize(com.apollographql.apollo.api/Executable<#A1>, kotlin.collections/Map, com.apollographql.cache.normalized.api/CacheKey = ..., com.apollographql.apollo.api/CustomScalarAdapters = ...): kotlin.collections/Map // com.apollographql.cache.normalized/ApolloStore.normalize|normalize(com.apollographql.apollo.api.Executable<0:0>;kotlin.collections.Map;com.apollographql.cache.normalized.api.CacheKey;com.apollographql.apollo.api.CustomScalarAdapters){0§}[0] - abstract fun <#A1: com.apollographql.apollo.api/Fragment.Data> readFragment(com.apollographql.apollo.api/Fragment<#A1>, com.apollographql.cache.normalized.api/CacheKey, com.apollographql.apollo.api/CustomScalarAdapters = ..., com.apollographql.cache.normalized.api/CacheHeaders = ...): com.apollographql.cache.normalized/ApolloStore.ReadResult<#A1> // com.apollographql.cache.normalized/ApolloStore.readFragment|readFragment(com.apollographql.apollo.api.Fragment<0:0>;com.apollographql.cache.normalized.api.CacheKey;com.apollographql.apollo.api.CustomScalarAdapters;com.apollographql.cache.normalized.api.CacheHeaders){0§}[0] - abstract fun <#A1: com.apollographql.apollo.api/Fragment.Data> writeFragment(com.apollographql.apollo.api/Fragment<#A1>, com.apollographql.cache.normalized.api/CacheKey, #A1, com.apollographql.apollo.api/CustomScalarAdapters = ..., com.apollographql.cache.normalized.api/CacheHeaders = ...): kotlin.collections/Set // com.apollographql.cache.normalized/ApolloStore.writeFragment|writeFragment(com.apollographql.apollo.api.Fragment<0:0>;com.apollographql.cache.normalized.api.CacheKey;0:0;com.apollographql.apollo.api.CustomScalarAdapters;com.apollographql.cache.normalized.api.CacheHeaders){0§}[0] - abstract fun <#A1: com.apollographql.apollo.api/Fragment.Data> writeOptimisticUpdates(com.apollographql.apollo.api/Fragment<#A1>, com.apollographql.cache.normalized.api/CacheKey, #A1, com.benasher44.uuid/Uuid, com.apollographql.apollo.api/CustomScalarAdapters = ...): kotlin.collections/Set // com.apollographql.cache.normalized/ApolloStore.writeOptimisticUpdates|writeOptimisticUpdates(com.apollographql.apollo.api.Fragment<0:0>;com.apollographql.cache.normalized.api.CacheKey;0:0;com.benasher44.uuid.Uuid;com.apollographql.apollo.api.CustomScalarAdapters){0§}[0] - abstract fun <#A1: com.apollographql.apollo.api/Operation.Data> readOperation(com.apollographql.apollo.api/Operation<#A1>, com.apollographql.apollo.api/CustomScalarAdapters = ..., com.apollographql.cache.normalized.api/CacheHeaders = ...): com.apollographql.apollo.api/ApolloResponse<#A1> // com.apollographql.cache.normalized/ApolloStore.readOperation|readOperation(com.apollographql.apollo.api.Operation<0:0>;com.apollographql.apollo.api.CustomScalarAdapters;com.apollographql.cache.normalized.api.CacheHeaders){0§}[0] - abstract fun <#A1: com.apollographql.apollo.api/Operation.Data> writeOperation(com.apollographql.apollo.api/Operation<#A1>, #A1, kotlin.collections/List? = ..., com.apollographql.apollo.api/CustomScalarAdapters = ..., com.apollographql.cache.normalized.api/CacheHeaders = ...): kotlin.collections/Set // com.apollographql.cache.normalized/ApolloStore.writeOperation|writeOperation(com.apollographql.apollo.api.Operation<0:0>;0:0;kotlin.collections.List?;com.apollographql.apollo.api.CustomScalarAdapters;com.apollographql.cache.normalized.api.CacheHeaders){0§}[0] - abstract fun <#A1: com.apollographql.apollo.api/Operation.Data> writeOperation(com.apollographql.apollo.api/Operation<#A1>, kotlin.collections/Map, com.apollographql.apollo.api/CustomScalarAdapters = ..., com.apollographql.cache.normalized.api/CacheHeaders = ...): kotlin.collections/Set // com.apollographql.cache.normalized/ApolloStore.writeOperation|writeOperation(com.apollographql.apollo.api.Operation<0:0>;kotlin.collections.Map;com.apollographql.apollo.api.CustomScalarAdapters;com.apollographql.cache.normalized.api.CacheHeaders){0§}[0] - abstract fun <#A1: com.apollographql.apollo.api/Operation.Data> writeOptimisticUpdates(com.apollographql.apollo.api/Operation<#A1>, #A1, com.benasher44.uuid/Uuid, com.apollographql.apollo.api/CustomScalarAdapters = ...): kotlin.collections/Set // com.apollographql.cache.normalized/ApolloStore.writeOptimisticUpdates|writeOptimisticUpdates(com.apollographql.apollo.api.Operation<0:0>;0:0;com.benasher44.uuid.Uuid;com.apollographql.apollo.api.CustomScalarAdapters){0§}[0] - abstract fun <#A1: kotlin/Any?> accessCache(kotlin/Function1): #A1 // com.apollographql.cache.normalized/ApolloStore.accessCache|accessCache(kotlin.Function1){0§}[0] - abstract fun clearAll(): kotlin/Boolean // com.apollographql.cache.normalized/ApolloStore.clearAll|clearAll(){}[0] - abstract fun dispose() // com.apollographql.cache.normalized/ApolloStore.dispose|dispose(){}[0] - abstract fun dump(): kotlin.collections/Map, kotlin.collections/Map> // com.apollographql.cache.normalized/ApolloStore.dump|dump(){}[0] - abstract fun remove(com.apollographql.cache.normalized.api/CacheKey, kotlin/Boolean = ...): kotlin/Boolean // com.apollographql.cache.normalized/ApolloStore.remove|remove(com.apollographql.cache.normalized.api.CacheKey;kotlin.Boolean){}[0] - abstract fun remove(kotlin.collections/List, kotlin/Boolean = ...): kotlin/Int // com.apollographql.cache.normalized/ApolloStore.remove|remove(kotlin.collections.List;kotlin.Boolean){}[0] - abstract fun rollbackOptimisticUpdates(com.benasher44.uuid/Uuid): kotlin.collections/Set // com.apollographql.cache.normalized/ApolloStore.rollbackOptimisticUpdates|rollbackOptimisticUpdates(com.benasher44.uuid.Uuid){}[0] - abstract fun trim(kotlin/Long, kotlin/Float = ...): kotlin/Long // com.apollographql.cache.normalized/ApolloStore.trim|trim(kotlin.Long;kotlin.Float){}[0] - abstract suspend fun publish(kotlin.collections/Set) // com.apollographql.cache.normalized/ApolloStore.publish|publish(kotlin.collections.Set){}[0] - - final class <#A1: com.apollographql.apollo.api/Executable.Data> ReadResult { // com.apollographql.cache.normalized/ApolloStore.ReadResult|null[0] - constructor (#A1, com.apollographql.cache.normalized.api/CacheHeaders) // com.apollographql.cache.normalized/ApolloStore.ReadResult.|(1:0;com.apollographql.cache.normalized.api.CacheHeaders){}[0] - - final val cacheHeaders // com.apollographql.cache.normalized/ApolloStore.ReadResult.cacheHeaders|{}cacheHeaders[0] - final fun (): com.apollographql.cache.normalized.api/CacheHeaders // com.apollographql.cache.normalized/ApolloStore.ReadResult.cacheHeaders.|(){}[0] - final val data // com.apollographql.cache.normalized/ApolloStore.ReadResult.data|{}data[0] - final fun (): #A1 // com.apollographql.cache.normalized/ApolloStore.ReadResult.data.|(){}[0] +abstract interface com.apollographql.cache.normalized/CacheManager { // com.apollographql.cache.normalized/CacheManager|null[0] + abstract val changedKeys // com.apollographql.cache.normalized/CacheManager.changedKeys|{}changedKeys[0] + abstract fun (): kotlinx.coroutines.flow/SharedFlow> // com.apollographql.cache.normalized/CacheManager.changedKeys.|(){}[0] + + abstract fun <#A1: com.apollographql.apollo.api/Executable.Data> normalize(com.apollographql.apollo.api/Executable<#A1>, kotlin.collections/Map, com.apollographql.cache.normalized.api/CacheKey = ..., com.apollographql.apollo.api/CustomScalarAdapters = ...): kotlin.collections/Map // com.apollographql.cache.normalized/CacheManager.normalize|normalize(com.apollographql.apollo.api.Executable<0:0>;kotlin.collections.Map;com.apollographql.cache.normalized.api.CacheKey;com.apollographql.apollo.api.CustomScalarAdapters){0§}[0] + abstract fun <#A1: com.apollographql.apollo.api/Fragment.Data> readFragment(com.apollographql.apollo.api/Fragment<#A1>, com.apollographql.cache.normalized.api/CacheKey, com.apollographql.apollo.api/CustomScalarAdapters = ..., com.apollographql.cache.normalized.api/CacheHeaders = ...): com.apollographql.cache.normalized/CacheManager.ReadResult<#A1> // com.apollographql.cache.normalized/CacheManager.readFragment|readFragment(com.apollographql.apollo.api.Fragment<0:0>;com.apollographql.cache.normalized.api.CacheKey;com.apollographql.apollo.api.CustomScalarAdapters;com.apollographql.cache.normalized.api.CacheHeaders){0§}[0] + abstract fun <#A1: com.apollographql.apollo.api/Fragment.Data> writeFragment(com.apollographql.apollo.api/Fragment<#A1>, com.apollographql.cache.normalized.api/CacheKey, #A1, com.apollographql.apollo.api/CustomScalarAdapters = ..., com.apollographql.cache.normalized.api/CacheHeaders = ...): kotlin.collections/Set // com.apollographql.cache.normalized/CacheManager.writeFragment|writeFragment(com.apollographql.apollo.api.Fragment<0:0>;com.apollographql.cache.normalized.api.CacheKey;0:0;com.apollographql.apollo.api.CustomScalarAdapters;com.apollographql.cache.normalized.api.CacheHeaders){0§}[0] + abstract fun <#A1: com.apollographql.apollo.api/Fragment.Data> writeOptimisticUpdates(com.apollographql.apollo.api/Fragment<#A1>, com.apollographql.cache.normalized.api/CacheKey, #A1, com.benasher44.uuid/Uuid, com.apollographql.apollo.api/CustomScalarAdapters = ...): kotlin.collections/Set // com.apollographql.cache.normalized/CacheManager.writeOptimisticUpdates|writeOptimisticUpdates(com.apollographql.apollo.api.Fragment<0:0>;com.apollographql.cache.normalized.api.CacheKey;0:0;com.benasher44.uuid.Uuid;com.apollographql.apollo.api.CustomScalarAdapters){0§}[0] + abstract fun <#A1: com.apollographql.apollo.api/Operation.Data> readOperation(com.apollographql.apollo.api/Operation<#A1>, com.apollographql.apollo.api/CustomScalarAdapters = ..., com.apollographql.cache.normalized.api/CacheHeaders = ...): com.apollographql.apollo.api/ApolloResponse<#A1> // com.apollographql.cache.normalized/CacheManager.readOperation|readOperation(com.apollographql.apollo.api.Operation<0:0>;com.apollographql.apollo.api.CustomScalarAdapters;com.apollographql.cache.normalized.api.CacheHeaders){0§}[0] + abstract fun <#A1: com.apollographql.apollo.api/Operation.Data> writeOperation(com.apollographql.apollo.api/Operation<#A1>, #A1, kotlin.collections/List? = ..., com.apollographql.apollo.api/CustomScalarAdapters = ..., com.apollographql.cache.normalized.api/CacheHeaders = ...): kotlin.collections/Set // com.apollographql.cache.normalized/CacheManager.writeOperation|writeOperation(com.apollographql.apollo.api.Operation<0:0>;0:0;kotlin.collections.List?;com.apollographql.apollo.api.CustomScalarAdapters;com.apollographql.cache.normalized.api.CacheHeaders){0§}[0] + abstract fun <#A1: com.apollographql.apollo.api/Operation.Data> writeOperation(com.apollographql.apollo.api/Operation<#A1>, kotlin.collections/Map, com.apollographql.apollo.api/CustomScalarAdapters = ..., com.apollographql.cache.normalized.api/CacheHeaders = ...): kotlin.collections/Set // com.apollographql.cache.normalized/CacheManager.writeOperation|writeOperation(com.apollographql.apollo.api.Operation<0:0>;kotlin.collections.Map;com.apollographql.apollo.api.CustomScalarAdapters;com.apollographql.cache.normalized.api.CacheHeaders){0§}[0] + abstract fun <#A1: com.apollographql.apollo.api/Operation.Data> writeOptimisticUpdates(com.apollographql.apollo.api/Operation<#A1>, #A1, com.benasher44.uuid/Uuid, com.apollographql.apollo.api/CustomScalarAdapters = ...): kotlin.collections/Set // com.apollographql.cache.normalized/CacheManager.writeOptimisticUpdates|writeOptimisticUpdates(com.apollographql.apollo.api.Operation<0:0>;0:0;com.benasher44.uuid.Uuid;com.apollographql.apollo.api.CustomScalarAdapters){0§}[0] + abstract fun <#A1: kotlin/Any?> accessCache(kotlin/Function1): #A1 // com.apollographql.cache.normalized/CacheManager.accessCache|accessCache(kotlin.Function1){0§}[0] + abstract fun clearAll(): kotlin/Boolean // com.apollographql.cache.normalized/CacheManager.clearAll|clearAll(){}[0] + abstract fun dispose() // com.apollographql.cache.normalized/CacheManager.dispose|dispose(){}[0] + abstract fun dump(): kotlin.collections/Map, kotlin.collections/Map> // com.apollographql.cache.normalized/CacheManager.dump|dump(){}[0] + abstract fun remove(com.apollographql.cache.normalized.api/CacheKey, kotlin/Boolean = ...): kotlin/Boolean // com.apollographql.cache.normalized/CacheManager.remove|remove(com.apollographql.cache.normalized.api.CacheKey;kotlin.Boolean){}[0] + abstract fun remove(kotlin.collections/List, kotlin/Boolean = ...): kotlin/Int // com.apollographql.cache.normalized/CacheManager.remove|remove(kotlin.collections.List;kotlin.Boolean){}[0] + abstract fun rollbackOptimisticUpdates(com.benasher44.uuid/Uuid): kotlin.collections/Set // com.apollographql.cache.normalized/CacheManager.rollbackOptimisticUpdates|rollbackOptimisticUpdates(com.benasher44.uuid.Uuid){}[0] + abstract fun trim(kotlin/Long, kotlin/Float = ...): kotlin/Long // com.apollographql.cache.normalized/CacheManager.trim|trim(kotlin.Long;kotlin.Float){}[0] + abstract suspend fun publish(kotlin.collections/Set) // com.apollographql.cache.normalized/CacheManager.publish|publish(kotlin.collections.Set){}[0] + + final class <#A1: com.apollographql.apollo.api/Executable.Data> ReadResult { // com.apollographql.cache.normalized/CacheManager.ReadResult|null[0] + constructor (#A1, com.apollographql.cache.normalized.api/CacheHeaders) // com.apollographql.cache.normalized/CacheManager.ReadResult.|(1:0;com.apollographql.cache.normalized.api.CacheHeaders){}[0] + + final val cacheHeaders // com.apollographql.cache.normalized/CacheManager.ReadResult.cacheHeaders|{}cacheHeaders[0] + final fun (): com.apollographql.cache.normalized.api/CacheHeaders // com.apollographql.cache.normalized/CacheManager.ReadResult.cacheHeaders.|(){}[0] + final val data // com.apollographql.cache.normalized/CacheManager.ReadResult.data|{}data[0] + final fun (): #A1 // com.apollographql.cache.normalized/CacheManager.ReadResult.data.|(){}[0] } - final object Companion { // com.apollographql.cache.normalized/ApolloStore.Companion|null[0] - final val ALL_KEYS // com.apollographql.cache.normalized/ApolloStore.Companion.ALL_KEYS|{}ALL_KEYS[0] - final fun (): kotlin.collections/AbstractSet // com.apollographql.cache.normalized/ApolloStore.Companion.ALL_KEYS.|(){}[0] + final object Companion { // com.apollographql.cache.normalized/CacheManager.Companion|null[0] + final val ALL_KEYS // com.apollographql.cache.normalized/CacheManager.Companion.ALL_KEYS|{}ALL_KEYS[0] + final fun (): kotlin.collections/AbstractSet // com.apollographql.cache.normalized/CacheManager.Companion.ALL_KEYS.|(){}[0] } } @@ -471,17 +471,17 @@ final class com.apollographql.cache.normalized/RemovedFieldsAndRecords { // com. } final class com.apollographql.cache.normalized/SimpleApolloStore { // com.apollographql.cache.normalized/SimpleApolloStore|null[0] - constructor (com.apollographql.cache.normalized/ApolloStore, com.apollographql.apollo.api/CustomScalarAdapters) // com.apollographql.cache.normalized/SimpleApolloStore.|(com.apollographql.cache.normalized.ApolloStore;com.apollographql.apollo.api.CustomScalarAdapters){}[0] + constructor (com.apollographql.cache.normalized/CacheManager, com.apollographql.apollo.api/CustomScalarAdapters) // com.apollographql.cache.normalized/SimpleApolloStore.|(com.apollographql.cache.normalized.CacheManager;com.apollographql.apollo.api.CustomScalarAdapters){}[0] - final val apolloStore // com.apollographql.cache.normalized/SimpleApolloStore.apolloStore|{}apolloStore[0] - final fun (): com.apollographql.cache.normalized/ApolloStore // com.apollographql.cache.normalized/SimpleApolloStore.apolloStore.|(){}[0] + final val cacheManager // com.apollographql.cache.normalized/SimpleApolloStore.cacheManager|{}cacheManager[0] + final fun (): com.apollographql.cache.normalized/CacheManager // com.apollographql.cache.normalized/SimpleApolloStore.cacheManager.|(){}[0] final val changedKeys // com.apollographql.cache.normalized/SimpleApolloStore.changedKeys|{}changedKeys[0] final fun (): kotlinx.coroutines.flow/SharedFlow> // com.apollographql.cache.normalized/SimpleApolloStore.changedKeys.|(){}[0] final val customScalarAdapters // com.apollographql.cache.normalized/SimpleApolloStore.customScalarAdapters|{}customScalarAdapters[0] final fun (): com.apollographql.apollo.api/CustomScalarAdapters // com.apollographql.cache.normalized/SimpleApolloStore.customScalarAdapters.|(){}[0] final fun <#A1: com.apollographql.apollo.api/Executable.Data> normalize(com.apollographql.apollo.api/Executable<#A1>, kotlin.collections/Map, com.apollographql.cache.normalized.api/CacheKey = ...): kotlin.collections/Map // com.apollographql.cache.normalized/SimpleApolloStore.normalize|normalize(com.apollographql.apollo.api.Executable<0:0>;kotlin.collections.Map;com.apollographql.cache.normalized.api.CacheKey){0§}[0] - final fun <#A1: com.apollographql.apollo.api/Fragment.Data> readFragment(com.apollographql.apollo.api/Fragment<#A1>, com.apollographql.cache.normalized.api/CacheKey, com.apollographql.cache.normalized.api/CacheHeaders = ...): com.apollographql.cache.normalized/ApolloStore.ReadResult<#A1> // com.apollographql.cache.normalized/SimpleApolloStore.readFragment|readFragment(com.apollographql.apollo.api.Fragment<0:0>;com.apollographql.cache.normalized.api.CacheKey;com.apollographql.cache.normalized.api.CacheHeaders){0§}[0] + final fun <#A1: com.apollographql.apollo.api/Fragment.Data> readFragment(com.apollographql.apollo.api/Fragment<#A1>, com.apollographql.cache.normalized.api/CacheKey, com.apollographql.cache.normalized.api/CacheHeaders = ...): com.apollographql.cache.normalized/CacheManager.ReadResult<#A1> // com.apollographql.cache.normalized/SimpleApolloStore.readFragment|readFragment(com.apollographql.apollo.api.Fragment<0:0>;com.apollographql.cache.normalized.api.CacheKey;com.apollographql.cache.normalized.api.CacheHeaders){0§}[0] final fun <#A1: com.apollographql.apollo.api/Fragment.Data> writeFragment(com.apollographql.apollo.api/Fragment<#A1>, com.apollographql.cache.normalized.api/CacheKey, #A1, com.apollographql.cache.normalized.api/CacheHeaders = ...): kotlin.collections/Set // com.apollographql.cache.normalized/SimpleApolloStore.writeFragment|writeFragment(com.apollographql.apollo.api.Fragment<0:0>;com.apollographql.cache.normalized.api.CacheKey;0:0;com.apollographql.cache.normalized.api.CacheHeaders){0§}[0] final fun <#A1: com.apollographql.apollo.api/Fragment.Data> writeOptimisticUpdates(com.apollographql.apollo.api/Fragment<#A1>, com.apollographql.cache.normalized.api/CacheKey, #A1, com.benasher44.uuid/Uuid): kotlin.collections/Set // com.apollographql.cache.normalized/SimpleApolloStore.writeOptimisticUpdates|writeOptimisticUpdates(com.apollographql.apollo.api.Fragment<0:0>;com.apollographql.cache.normalized.api.CacheKey;0:0;com.benasher44.uuid.Uuid){0§}[0] final fun <#A1: com.apollographql.apollo.api/Operation.Data> readOperation(com.apollographql.apollo.api/Operation<#A1>, com.apollographql.cache.normalized.api/CacheHeaders = ...): com.apollographql.apollo.api/ApolloResponse<#A1> // com.apollographql.cache.normalized/SimpleApolloStore.readOperation|readOperation(com.apollographql.apollo.api.Operation<0:0>;com.apollographql.cache.normalized.api.CacheHeaders){0§}[0] @@ -600,9 +600,9 @@ final val com.apollographql.cache.normalized/isFromCache // com.apollographql.ca final val com.apollographql.cache.normalized/store // com.apollographql.cache.normalized/store|@com.apollographql.apollo.ApolloClient{}store[0] final fun (com.apollographql.apollo/ApolloClient).(): com.apollographql.cache.normalized/SimpleApolloStore // com.apollographql.cache.normalized/store.|@com.apollographql.apollo.ApolloClient(){}[0] +final fun (com.apollographql.apollo/ApolloClient.Builder).com.apollographql.cache.normalized/cacheManager(com.apollographql.cache.normalized/CacheManager, kotlin/Boolean = ...): com.apollographql.apollo/ApolloClient.Builder // com.apollographql.cache.normalized/cacheManager|cacheManager@com.apollographql.apollo.ApolloClient.Builder(com.apollographql.cache.normalized.CacheManager;kotlin.Boolean){}[0] final fun (com.apollographql.apollo/ApolloClient.Builder).com.apollographql.cache.normalized/logCacheMisses(kotlin/Function1 = ...): com.apollographql.apollo/ApolloClient.Builder // com.apollographql.cache.normalized/logCacheMisses|logCacheMisses@com.apollographql.apollo.ApolloClient.Builder(kotlin.Function1){}[0] final fun (com.apollographql.apollo/ApolloClient.Builder).com.apollographql.cache.normalized/normalizedCache(com.apollographql.cache.normalized.api/NormalizedCacheFactory, com.apollographql.cache.normalized.api/CacheKeyGenerator = ..., com.apollographql.cache.normalized.api/MetadataGenerator = ..., com.apollographql.cache.normalized.api/CacheResolver = ..., com.apollographql.cache.normalized.api/RecordMerger = ..., com.apollographql.cache.normalized.api/FieldKeyGenerator = ..., com.apollographql.cache.normalized.api/EmbeddedFieldsProvider = ..., com.apollographql.cache.normalized.api/MaxAgeProvider = ..., kotlin/Boolean = ...): com.apollographql.apollo/ApolloClient.Builder // com.apollographql.cache.normalized/normalizedCache|normalizedCache@com.apollographql.apollo.ApolloClient.Builder(com.apollographql.cache.normalized.api.NormalizedCacheFactory;com.apollographql.cache.normalized.api.CacheKeyGenerator;com.apollographql.cache.normalized.api.MetadataGenerator;com.apollographql.cache.normalized.api.CacheResolver;com.apollographql.cache.normalized.api.RecordMerger;com.apollographql.cache.normalized.api.FieldKeyGenerator;com.apollographql.cache.normalized.api.EmbeddedFieldsProvider;com.apollographql.cache.normalized.api.MaxAgeProvider;kotlin.Boolean){}[0] -final fun (com.apollographql.apollo/ApolloClient.Builder).com.apollographql.cache.normalized/store(com.apollographql.cache.normalized/ApolloStore, kotlin/Boolean = ...): com.apollographql.apollo/ApolloClient.Builder // com.apollographql.cache.normalized/store|store@com.apollographql.apollo.ApolloClient.Builder(com.apollographql.cache.normalized.ApolloStore;kotlin.Boolean){}[0] final fun (com.apollographql.cache.normalized.api/NormalizedCache).com.apollographql.cache.normalized/allRecords(): kotlin.collections/Map // com.apollographql.cache.normalized/allRecords|allRecords@com.apollographql.cache.normalized.api.NormalizedCache(){}[0] final fun (com.apollographql.cache.normalized.api/NormalizedCache).com.apollographql.cache.normalized/garbageCollect(com.apollographql.cache.normalized.api/MaxAgeProvider, kotlin.time/Duration = ...): com.apollographql.cache.normalized/GarbageCollectResult // com.apollographql.cache.normalized/garbageCollect|garbageCollect@com.apollographql.cache.normalized.api.NormalizedCache(com.apollographql.cache.normalized.api.MaxAgeProvider;kotlin.time.Duration){}[0] final fun (com.apollographql.cache.normalized.api/NormalizedCache).com.apollographql.cache.normalized/removeDanglingReferences(): com.apollographql.cache.normalized/RemovedFieldsAndRecords // com.apollographql.cache.normalized/removeDanglingReferences|removeDanglingReferences@com.apollographql.cache.normalized.api.NormalizedCache(){}[0] @@ -642,4 +642,4 @@ final fun <#A: kotlin/Any?> (com.apollographql.apollo.api/MutableExecutionOption final fun <#A: kotlin/Any?> (com.apollographql.apollo.api/MutableExecutionOptions<#A>).com.apollographql.cache.normalized/storePartialResponses(kotlin/Boolean): kotlin/Nothing // com.apollographql.cache.normalized/storePartialResponses|storePartialResponses@com.apollographql.apollo.api.MutableExecutionOptions<0:0>(kotlin.Boolean){0§}[0] final fun <#A: kotlin/Any?> (com.apollographql.apollo.api/MutableExecutionOptions<#A>).com.apollographql.cache.normalized/storeReceivedDate(kotlin/Boolean): #A // com.apollographql.cache.normalized/storeReceivedDate|storeReceivedDate@com.apollographql.apollo.api.MutableExecutionOptions<0:0>(kotlin.Boolean){0§}[0] final fun <#A: kotlin/Any?> (com.apollographql.apollo.api/MutableExecutionOptions<#A>).com.apollographql.cache.normalized/writeToCacheAsynchronously(kotlin/Boolean): #A // com.apollographql.cache.normalized/writeToCacheAsynchronously|writeToCacheAsynchronously@com.apollographql.apollo.api.MutableExecutionOptions<0:0>(kotlin.Boolean){0§}[0] -final fun com.apollographql.cache.normalized/ApolloStore(com.apollographql.cache.normalized.api/NormalizedCacheFactory, com.apollographql.cache.normalized.api/CacheKeyGenerator = ..., com.apollographql.cache.normalized.api/MetadataGenerator = ..., com.apollographql.cache.normalized.api/CacheResolver = ..., com.apollographql.cache.normalized.api/RecordMerger = ..., com.apollographql.cache.normalized.api/FieldKeyGenerator = ..., com.apollographql.cache.normalized.api/EmbeddedFieldsProvider = ..., com.apollographql.cache.normalized.api/MaxAgeProvider = ...): com.apollographql.cache.normalized/ApolloStore // com.apollographql.cache.normalized/ApolloStore|ApolloStore(com.apollographql.cache.normalized.api.NormalizedCacheFactory;com.apollographql.cache.normalized.api.CacheKeyGenerator;com.apollographql.cache.normalized.api.MetadataGenerator;com.apollographql.cache.normalized.api.CacheResolver;com.apollographql.cache.normalized.api.RecordMerger;com.apollographql.cache.normalized.api.FieldKeyGenerator;com.apollographql.cache.normalized.api.EmbeddedFieldsProvider;com.apollographql.cache.normalized.api.MaxAgeProvider){}[0] +final fun com.apollographql.cache.normalized/CacheManager(com.apollographql.cache.normalized.api/NormalizedCacheFactory, com.apollographql.cache.normalized.api/CacheKeyGenerator = ..., com.apollographql.cache.normalized.api/MetadataGenerator = ..., com.apollographql.cache.normalized.api/CacheResolver = ..., com.apollographql.cache.normalized.api/RecordMerger = ..., com.apollographql.cache.normalized.api/FieldKeyGenerator = ..., com.apollographql.cache.normalized.api/EmbeddedFieldsProvider = ..., com.apollographql.cache.normalized.api/MaxAgeProvider = ...): com.apollographql.cache.normalized/CacheManager // com.apollographql.cache.normalized/CacheManager|CacheManager(com.apollographql.cache.normalized.api.NormalizedCacheFactory;com.apollographql.cache.normalized.api.CacheKeyGenerator;com.apollographql.cache.normalized.api.MetadataGenerator;com.apollographql.cache.normalized.api.CacheResolver;com.apollographql.cache.normalized.api.RecordMerger;com.apollographql.cache.normalized.api.FieldKeyGenerator;com.apollographql.cache.normalized.api.EmbeddedFieldsProvider;com.apollographql.cache.normalized.api.MaxAgeProvider){}[0] diff --git a/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/ApolloStore.kt b/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/CacheManager.kt similarity index 95% rename from normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/ApolloStore.kt rename to normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/CacheManager.kt index 069d20ee..2464616c 100644 --- a/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/ApolloStore.kt +++ b/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/CacheManager.kt @@ -7,8 +7,7 @@ import com.apollographql.apollo.api.Executable import com.apollographql.apollo.api.Fragment import com.apollographql.apollo.api.Operation import com.apollographql.apollo.api.json.JsonNumber -import com.apollographql.apollo.interceptor.ApolloInterceptor -import com.apollographql.cache.normalized.ApolloStore.Companion.ALL_KEYS +import com.apollographql.cache.normalized.CacheManager.Companion.ALL_KEYS import com.apollographql.cache.normalized.api.CacheHeaders import com.apollographql.cache.normalized.api.CacheKey import com.apollographql.cache.normalized.api.CacheKeyGenerator @@ -30,20 +29,20 @@ import com.apollographql.cache.normalized.api.Record import com.apollographql.cache.normalized.api.RecordMerger import com.apollographql.cache.normalized.api.RecordValue import com.apollographql.cache.normalized.api.TypePolicyCacheKeyGenerator -import com.apollographql.cache.normalized.internal.DefaultApolloStore +import com.apollographql.cache.normalized.internal.DefaultCacheManager import com.benasher44.uuid.Uuid import kotlinx.coroutines.flow.SharedFlow import kotlin.reflect.KClass /** - * ApolloStore exposes a high-level API to access a [com.apollographql.cache.normalized.api.NormalizedCache]. + * CacheManager exposes a high-level API to access a [com.apollographql.cache.normalized.api.NormalizedCache]. * * Note that most operations are synchronous and might block if the underlying cache is doing IO - calling them from the main thread * should be avoided. * * Note that changes are not automatically published - call [publish] to notify any watchers. */ -interface ApolloStore { +interface CacheManager { /** * Exposes the record field keys that have changed. This is collected internally to notify watchers. * @@ -326,7 +325,7 @@ interface ApolloStore { ) } -fun ApolloStore( +fun CacheManager( normalizedCacheFactory: NormalizedCacheFactory, cacheKeyGenerator: CacheKeyGenerator = TypePolicyCacheKeyGenerator, metadataGenerator: MetadataGenerator = EmptyMetadataGenerator, @@ -335,7 +334,7 @@ fun ApolloStore( fieldKeyGenerator: FieldKeyGenerator = DefaultFieldKeyGenerator, embeddedFieldsProvider: EmbeddedFieldsProvider = DefaultEmbeddedFieldsProvider, maxAgeProvider: MaxAgeProvider = DefaultMaxAgeProvider, -): ApolloStore = DefaultApolloStore( +): CacheManager = DefaultCacheManager( normalizedCacheFactory = normalizedCacheFactory, cacheKeyGenerator = cacheKeyGenerator, metadataGenerator = metadataGenerator, @@ -346,12 +345,7 @@ fun ApolloStore( maxAgeProvider = maxAgeProvider, ) -/** - * Interface that marks all interceptors added when configuring a `store()` on ApolloClient.Builder. - */ -internal interface ApolloStoreInterceptor : ApolloInterceptor - -internal fun ApolloStore.cacheDumpProvider(): () -> Map>>> { +internal fun CacheManager.cacheDumpProvider(): () -> Map>>> { return { dump().map { (cacheClass, cacheRecords) -> cacheClass.normalizedCacheName() to cacheRecords diff --git a/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/ClientCacheExtensions.kt b/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/ClientCacheExtensions.kt index ff9063bf..a635135c 100644 --- a/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/ClientCacheExtensions.kt +++ b/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/ClientCacheExtensions.kt @@ -74,8 +74,8 @@ fun ApolloClient.Builder.normalizedCache( maxAgeProvider: MaxAgeProvider = DefaultMaxAgeProvider, writeToCacheAsynchronously: Boolean = false, ): ApolloClient.Builder { - return store( - ApolloStore( + return cacheManager( + CacheManager( normalizedCacheFactory = normalizedCacheFactory, cacheKeyGenerator = cacheKeyGenerator, metadataGenerator = metadataGenerator, @@ -123,11 +123,11 @@ private fun ApolloInterceptorChain.asInterceptor(): ApolloInterceptor { } } -internal class CacheInterceptor(val store: ApolloStore) : ApolloInterceptor { +internal class CacheInterceptor(val cacheManager: CacheManager) : ApolloInterceptor { private val delegates = listOf( - WatcherInterceptor(store), + WatcherInterceptor(cacheManager), FetchPolicyRouterInterceptor, - ApolloCacheInterceptor(store), + ApolloCacheInterceptor(cacheManager), StoreExpirationDateInterceptor, ) @@ -139,10 +139,10 @@ internal class CacheInterceptor(val store: ApolloStore) : ApolloInterceptor { } } -fun ApolloClient.Builder.store(store: ApolloStore, writeToCacheAsynchronously: Boolean = false): ApolloClient.Builder { - return cacheInterceptor(CacheInterceptor(store)) +fun ApolloClient.Builder.cacheManager(cacheManager: CacheManager, writeToCacheAsynchronously: Boolean = false): ApolloClient.Builder { + return cacheInterceptor(CacheInterceptor(cacheManager)) .writeToCacheAsynchronously(writeToCacheAsynchronously) - .addExecutionContext(CacheDumpProviderContext(store.cacheDumpProvider())) + .addExecutionContext(CacheDumpProviderContext(cacheManager.cacheDumpProvider())) } /** @@ -153,7 +153,7 @@ fun ApolloClient.Builder.store(store: ApolloStore, writeToCacheAsynchronously: B * * [fetchPolicy] controls how the result is first queried, while [refetchPolicy] will control the subsequent fetches. * - * Note: when manually updating the cache through [ApolloStore], [ApolloStore.publish] must be called for watchers to be notified. + * Note: when manually updating the cache through [CacheManager], [CacheManager.publish] must be called for watchers to be notified. * * @see fetchPolicy * @see refetchPolicy @@ -229,7 +229,7 @@ val ApolloClient.apolloStore: SimpleApolloStore val ApolloClient.store: SimpleApolloStore get() { return (cacheInterceptor as? CacheInterceptor)?.let { - SimpleApolloStore(it.store, customScalarAdapters) + SimpleApolloStore(it.cacheManager, customScalarAdapters) } ?: error("No store configured") } diff --git a/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/FetchPolicyInterceptors.kt b/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/FetchPolicyInterceptors.kt index 28433131..5cc02da5 100644 --- a/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/FetchPolicyInterceptors.kt +++ b/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/FetchPolicyInterceptors.kt @@ -150,7 +150,7 @@ fun ApolloResponse.errorsAsException(): ApolloResponse intercept(request: ApolloRequest, chain: ApolloInterceptorChain): Flow> { if (request.operation !is Query) { // Subscriptions and Mutations do not support fetchPolicies diff --git a/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/SimpleApolloStore.kt b/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/SimpleApolloStore.kt index b5d731f8..77388fd0 100644 --- a/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/SimpleApolloStore.kt +++ b/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/SimpleApolloStore.kt @@ -6,7 +6,7 @@ import com.apollographql.apollo.api.Error import com.apollographql.apollo.api.Executable import com.apollographql.apollo.api.Fragment import com.apollographql.apollo.api.Operation -import com.apollographql.cache.normalized.ApolloStore.ReadResult +import com.apollographql.cache.normalized.CacheManager.ReadResult import com.apollographql.cache.normalized.api.CacheHeaders import com.apollographql.cache.normalized.api.CacheKey import com.apollographql.cache.normalized.api.DataWithErrors @@ -17,38 +17,38 @@ import kotlinx.coroutines.flow.SharedFlow import kotlin.reflect.KClass /** - * A wrapper around [ApolloStore] that provides a simplified API for reading and writing data. + * A wrapper around [CacheManager] that provides a simplified API for reading and writing data. */ class SimpleApolloStore( - val apolloStore: ApolloStore, + val cacheManager: CacheManager, val customScalarAdapters: CustomScalarAdapters, ) { /** - * @see ApolloStore.changedKeys + * @see CacheManager.changedKeys */ val changedKeys: SharedFlow> - get() = apolloStore.changedKeys + get() = cacheManager.changedKeys /** - * @see ApolloStore.readOperation + * @see CacheManager.readOperation */ fun readOperation( operation: Operation, cacheHeaders: CacheHeaders = CacheHeaders.NONE, - ): ApolloResponse = apolloStore.readOperation( + ): ApolloResponse = cacheManager.readOperation( operation = operation, cacheHeaders = cacheHeaders, customScalarAdapters = customScalarAdapters, ) /** - * @see ApolloStore.readFragment + * @see CacheManager.readFragment */ fun readFragment( fragment: Fragment, cacheKey: CacheKey, cacheHeaders: CacheHeaders = CacheHeaders.NONE, - ): ReadResult = apolloStore.readFragment( + ): ReadResult = cacheManager.readFragment( fragment = fragment, cacheKey = cacheKey, customScalarAdapters = customScalarAdapters, @@ -56,14 +56,14 @@ class SimpleApolloStore( ) /** - * @see ApolloStore.writeOperation + * @see CacheManager.writeOperation */ fun writeOperation( operation: Operation, data: D, errors: List? = null, cacheHeaders: CacheHeaders = CacheHeaders.NONE, - ): Set = apolloStore.writeOperation( + ): Set = cacheManager.writeOperation( operation = operation, data = data, errors = errors, @@ -72,13 +72,13 @@ class SimpleApolloStore( ) /** - * @see ApolloStore.writeFragment + * @see CacheManager.writeFragment */ fun writeOperation( operation: Operation, dataWithErrors: DataWithErrors, cacheHeaders: CacheHeaders = CacheHeaders.NONE, - ): Set = apolloStore.writeOperation( + ): Set = cacheManager.writeOperation( operation = operation, dataWithErrors = dataWithErrors, cacheHeaders = cacheHeaders, @@ -86,14 +86,14 @@ class SimpleApolloStore( ) /** - * @see ApolloStore.writeFragment + * @see CacheManager.writeFragment */ fun writeFragment( fragment: Fragment, cacheKey: CacheKey, data: D, cacheHeaders: CacheHeaders = CacheHeaders.NONE, - ): Set = apolloStore.writeFragment( + ): Set = cacheManager.writeFragment( fragment = fragment, cacheKey = cacheKey, data = data, @@ -102,13 +102,13 @@ class SimpleApolloStore( ) /** - * @see ApolloStore.writeOptimisticUpdates + * @see CacheManager.writeOptimisticUpdates */ fun writeOptimisticUpdates( operation: Operation, data: D, mutationId: Uuid, - ): Set = apolloStore.writeOptimisticUpdates( + ): Set = cacheManager.writeOptimisticUpdates( operation = operation, data = data, mutationId = mutationId, @@ -116,14 +116,14 @@ class SimpleApolloStore( ) /** - * @see ApolloStore.writeOptimisticUpdates + * @see CacheManager.writeOptimisticUpdates */ fun writeOptimisticUpdates( fragment: Fragment, cacheKey: CacheKey, data: D, mutationId: Uuid, - ): Set = apolloStore.writeOptimisticUpdates( + ): Set = cacheManager.writeOptimisticUpdates( fragment = fragment, cacheKey = cacheKey, data = data, @@ -132,38 +132,38 @@ class SimpleApolloStore( ) /** - * @see ApolloStore.rollbackOptimisticUpdates + * @see CacheManager.rollbackOptimisticUpdates */ - fun rollbackOptimisticUpdates(mutationId: Uuid): Set = apolloStore.rollbackOptimisticUpdates(mutationId) + fun rollbackOptimisticUpdates(mutationId: Uuid): Set = cacheManager.rollbackOptimisticUpdates(mutationId) /** - * @see ApolloStore.clearAll + * @see CacheManager.clearAll */ - fun clearAll(): Boolean = apolloStore.clearAll() + fun clearAll(): Boolean = cacheManager.clearAll() /** - * @see ApolloStore.remove + * @see CacheManager.remove */ - fun remove(cacheKey: CacheKey, cascade: Boolean = true): Boolean = apolloStore.remove(cacheKey, cascade) + fun remove(cacheKey: CacheKey, cascade: Boolean = true): Boolean = cacheManager.remove(cacheKey, cascade) /** - * @see ApolloStore.remove + * @see CacheManager.remove */ - fun remove(cacheKeys: List, cascade: Boolean = true): Int = apolloStore.remove(cacheKeys, cascade) + fun remove(cacheKeys: List, cascade: Boolean = true): Int = cacheManager.remove(cacheKeys, cascade) /** - * @see ApolloStore.trim + * @see CacheManager.trim */ - fun trim(maxSizeBytes: Long, trimFactor: Float = 0.1f): Long = apolloStore.trim(maxSizeBytes, trimFactor) + fun trim(maxSizeBytes: Long, trimFactor: Float = 0.1f): Long = cacheManager.trim(maxSizeBytes, trimFactor) /** - * @see ApolloStore.normalize + * @see CacheManager.normalize */ fun normalize( executable: Executable, dataWithErrors: DataWithErrors, rootKey: CacheKey = CacheKey.QUERY_ROOT, - ): Map = apolloStore.normalize( + ): Map = cacheManager.normalize( executable = executable, dataWithErrors = dataWithErrors, rootKey = rootKey, @@ -171,22 +171,22 @@ class SimpleApolloStore( ) /** - * @see ApolloStore.publish + * @see CacheManager.publish */ - suspend fun publish(keys: Set) = apolloStore.publish(keys) + suspend fun publish(keys: Set) = cacheManager.publish(keys) /** - * @see ApolloStore.publish + * @see CacheManager.publish */ - fun accessCache(block: (NormalizedCache) -> R): R = apolloStore.accessCache(block) + fun accessCache(block: (NormalizedCache) -> R): R = cacheManager.accessCache(block) /** - * @see ApolloStore.dump + * @see CacheManager.dump */ - fun dump(): Map, Map> = apolloStore.dump() + fun dump(): Map, Map> = cacheManager.dump() /** - * @see ApolloStore.dispose + * @see CacheManager.dispose */ - fun dispose() = apolloStore.dispose() + fun dispose() = cacheManager.dispose() } diff --git a/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/api/ApolloCacheHeaders.kt b/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/api/ApolloCacheHeaders.kt index 65c72f16..bf524db0 100644 --- a/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/api/ApolloCacheHeaders.kt +++ b/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/api/ApolloCacheHeaders.kt @@ -14,7 +14,7 @@ object ApolloCacheHeaders { */ const val MEMORY_CACHE_ONLY = "memory-cache-only" - @Deprecated(level = DeprecationLevel.ERROR, message = "This header has no effect and will be removed in a future release. Use ApolloStore.remove() instead.") + @Deprecated(level = DeprecationLevel.ERROR, message = "This header has no effect and will be removed in a future release. Use CacheManager.remove() instead.") const val EVICT_AFTER_READ = "evict-after-read" /** diff --git a/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/internal/ApolloCacheInterceptor.kt b/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/internal/ApolloCacheInterceptor.kt index e2b546e0..1a46d835 100644 --- a/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/internal/ApolloCacheInterceptor.kt +++ b/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/internal/ApolloCacheInterceptor.kt @@ -14,9 +14,8 @@ import com.apollographql.apollo.exception.apolloExceptionHandler import com.apollographql.apollo.interceptor.ApolloInterceptor import com.apollographql.apollo.interceptor.ApolloInterceptorChain import com.apollographql.apollo.mpp.currentTimeMillis -import com.apollographql.cache.normalized.ApolloStore -import com.apollographql.cache.normalized.ApolloStoreInterceptor import com.apollographql.cache.normalized.CacheInfo +import com.apollographql.cache.normalized.CacheManager import com.apollographql.cache.normalized.api.ApolloCacheHeaders import com.apollographql.cache.normalized.api.CacheHeaders import com.apollographql.cache.normalized.cacheHeaders @@ -36,8 +35,8 @@ import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.launch internal class ApolloCacheInterceptor( - val store: ApolloStore, -) : ApolloInterceptor, ApolloStoreInterceptor { + val cacheManager: CacheManager, +) : ApolloInterceptor { private suspend fun maybeAsync(request: ApolloRequest, block: suspend () -> Unit) { if (request.writeToCacheAsynchronously) { val scope = request.executionContext[ConcurrencyInfo]!!.coroutineScope @@ -80,11 +79,11 @@ internal class ApolloCacheInterceptor( if (request.errorsReplaceCachedValues) { cacheHeaders += CacheHeaders.Builder().addHeader(ApolloCacheHeaders.ERRORS_REPLACE_CACHED_VALUES, "true").build() } - store.writeOperation(request.operation, response.data!!, response.errors, customScalarAdapters, cacheHeaders) + cacheManager.writeOperation(request.operation, response.data!!, response.errors, customScalarAdapters, cacheHeaders) } else { emptySet() } - store.publish(cacheKeys + extraKeys) + cacheManager.publish(cacheKeys + extraKeys) } } @@ -139,12 +138,12 @@ internal class ApolloCacheInterceptor( val optimisticData = request.optimisticData if (optimisticData != null) { @Suppress("UNCHECKED_CAST") - store.writeOptimisticUpdates( + cacheManager.writeOptimisticUpdates( operation = request.operation, data = optimisticData as D, mutationId = request.requestUuid, customScalarAdapters = customScalarAdapters, - ).also { store.publish(it) } + ).also { cacheManager.publish(it) } } /** @@ -165,7 +164,7 @@ internal class ApolloCacheInterceptor( } previousResponse = response if (optimisticKeys == null) optimisticKeys = if (optimisticData != null) { - store.rollbackOptimisticUpdates(request.requestUuid) + cacheManager.rollbackOptimisticUpdates(request.requestUuid) } else { emptySet() } @@ -176,12 +175,12 @@ internal class ApolloCacheInterceptor( if (networkException != null) { if (optimisticKeys == null) optimisticKeys = if (optimisticData != null) { - store.rollbackOptimisticUpdates(request.requestUuid) + cacheManager.rollbackOptimisticUpdates(request.requestUuid) } else { emptySet() } - store.publish(optimisticKeys) + cacheManager.publish(optimisticKeys) } } } @@ -208,7 +207,7 @@ internal class ApolloCacheInterceptor( cacheHeaders += CacheHeaders.Builder().addHeader(ApolloCacheHeaders.MEMORY_CACHE_ONLY, "true").build() } val startMillis = currentTimeMillis() - val response = store.readOperation( + val response = cacheManager.readOperation( operation = request.operation, customScalarAdapters = customScalarAdapters, cacheHeaders = cacheHeaders, diff --git a/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/internal/DefaultApolloStore.kt b/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/internal/DefaultCacheManager.kt similarity index 98% rename from normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/internal/DefaultApolloStore.kt rename to normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/internal/DefaultCacheManager.kt index d4e4e99b..16b6c83c 100644 --- a/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/internal/DefaultApolloStore.kt +++ b/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/internal/DefaultCacheManager.kt @@ -9,9 +9,9 @@ import com.apollographql.apollo.api.Operation import com.apollographql.apollo.api.json.ApolloJsonElement import com.apollographql.apollo.api.json.jsonReader import com.apollographql.apollo.api.variables -import com.apollographql.cache.normalized.ApolloStore -import com.apollographql.cache.normalized.ApolloStore.ReadResult import com.apollographql.cache.normalized.CacheInfo +import com.apollographql.cache.normalized.CacheManager +import com.apollographql.cache.normalized.CacheManager.ReadResult import com.apollographql.cache.normalized.api.ApolloCacheHeaders import com.apollographql.cache.normalized.api.CacheHeaders import com.apollographql.cache.normalized.api.CacheKey @@ -38,7 +38,7 @@ import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.asSharedFlow import kotlin.reflect.KClass -internal class DefaultApolloStore( +internal class DefaultCacheManager( normalizedCacheFactory: NormalizedCacheFactory, private val cacheKeyGenerator: CacheKeyGenerator, private val fieldKeyGenerator: FieldKeyGenerator, @@ -47,7 +47,7 @@ internal class DefaultApolloStore( private val recordMerger: RecordMerger, private val embeddedFieldsProvider: EmbeddedFieldsProvider, private val maxAgeProvider: MaxAgeProvider, -) : ApolloStore { +) : CacheManager { private val changedKeysEvents = MutableSharedFlow>( /** * The '64' magic number here is a potential code smell @@ -78,7 +78,7 @@ internal class DefaultApolloStore( } override suspend fun publish(keys: Set) { - if (keys.isEmpty() && keys !== ApolloStore.ALL_KEYS) { + if (keys.isEmpty() && keys !== CacheManager.ALL_KEYS) { return } diff --git a/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/internal/WatcherInterceptor.kt b/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/internal/WatcherInterceptor.kt index 2af3ad45..4eabe158 100644 --- a/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/internal/WatcherInterceptor.kt +++ b/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/internal/WatcherInterceptor.kt @@ -8,8 +8,7 @@ import com.apollographql.apollo.api.Query import com.apollographql.apollo.exception.DefaultApolloException import com.apollographql.apollo.interceptor.ApolloInterceptor import com.apollographql.apollo.interceptor.ApolloInterceptorChain -import com.apollographql.cache.normalized.ApolloStore -import com.apollographql.cache.normalized.ApolloStoreInterceptor +import com.apollographql.cache.normalized.CacheManager import com.apollographql.cache.normalized.api.CacheKey import com.apollographql.cache.normalized.api.dependentKeys import com.apollographql.cache.normalized.api.withErrors @@ -26,7 +25,7 @@ import kotlinx.coroutines.flow.onSubscription internal val WatcherSentinel = DefaultApolloException("The watcher has started") -internal class WatcherInterceptor(val store: ApolloStore) : ApolloInterceptor, ApolloStoreInterceptor { +internal class WatcherInterceptor(val cacheManager: CacheManager) : ApolloInterceptor { override fun intercept(request: ApolloRequest, chain: ApolloInterceptorChain): Flow> { val watchContext = request.watchContext ?: return chain.proceed(request) @@ -44,7 +43,7 @@ internal class WatcherInterceptor(val store: ApolloStore) : ApolloInterceptor, A errors = null, customScalarAdapters = customScalarAdapters, ) - store.normalize( + cacheManager.normalize( executable = request.operation, dataWithErrors = dataWithErrors, rootKey = CacheKey.QUERY_ROOT, @@ -52,13 +51,13 @@ internal class WatcherInterceptor(val store: ApolloStore) : ApolloInterceptor, A ).values.dependentKeys() } - return (store.changedKeys as SharedFlow) + return (cacheManager.changedKeys as SharedFlow) .onSubscription { emit(Unit) } .filter { changedKeys -> changedKeys !is Set<*> || - changedKeys === ApolloStore.ALL_KEYS || + changedKeys === CacheManager.ALL_KEYS || watchedKeys == null || changedKeys.intersect(watchedKeys!!).isNotEmpty() }.map { @@ -73,7 +72,7 @@ internal class WatcherInterceptor(val store: ApolloStore) : ApolloInterceptor, A errors = response.errors, customScalarAdapters = customScalarAdapters, ) - watchedKeys = store.normalize( + watchedKeys = cacheManager.normalize( executable = request.operation, dataWithErrors = dataWithErrors, rootKey = CacheKey.QUERY_ROOT, diff --git a/normalized-cache/src/commonTest/kotlin/com/apollographql/cache/normalized/MemoryCacheTest.kt b/normalized-cache/src/commonTest/kotlin/com/apollographql/cache/normalized/MemoryCacheTest.kt index b2fbb5b1..37d5e92e 100644 --- a/normalized-cache/src/commonTest/kotlin/com/apollographql/cache/normalized/MemoryCacheTest.kt +++ b/normalized-cache/src/commonTest/kotlin/com/apollographql/cache/normalized/MemoryCacheTest.kt @@ -278,8 +278,8 @@ class MemoryCacheTest { return MemoryCache(maxSizeBytes = maxSizeBytes, expireAfterMillis = expireAfterMillis, nextCache = nextCache) } - private fun assertTestRecordPresentAndAccurate(testRecord: Record, store: NormalizedCache) { - val cacheRecord = checkNotNull(store.loadRecord(testRecord.key, CacheHeaders.NONE)) + private fun assertTestRecordPresentAndAccurate(testRecord: Record, cache: NormalizedCache) { + val cacheRecord = checkNotNull(cache.loadRecord(testRecord.key, CacheHeaders.NONE)) assertEquals(testRecord.key, cacheRecord.key) assertEquals(testRecord.fields, cacheRecord.fields) } diff --git a/samples/pagination/pagination-support/README.md b/samples/pagination/pagination-support/README.md index f08a2b9f..1a68ef2d 100644 --- a/samples/pagination/pagination-support/README.md +++ b/samples/pagination/pagination-support/README.md @@ -17,8 +17,8 @@ Note: to execute the app, provide a [GitHub access token](https://developer.gith ``` and the cache declaration in `Apollo.kt`: ```kotlin - .store( - ApolloStore( + .cacheManager( + CacheManager( normalizedCacheFactory = memoryThenSqlCache, cacheKeyGenerator = TypePolicyCacheKeyGenerator, metadataGenerator = ConnectionMetadataGenerator(Pagination.connectionTypes), // Use the generated Pagination class diff --git a/tests/defer/src/commonTest/kotlin/test/DeferNormalizedCacheTest.kt b/tests/defer/src/commonTest/kotlin/test/DeferNormalizedCacheTest.kt index 183c7b97..f10904b2 100644 --- a/tests/defer/src/commonTest/kotlin/test/DeferNormalizedCacheTest.kt +++ b/tests/defer/src/commonTest/kotlin/test/DeferNormalizedCacheTest.kt @@ -11,10 +11,11 @@ import com.apollographql.apollo.exception.ApolloHttpException import com.apollographql.apollo.exception.ApolloNetworkException import com.apollographql.apollo.exception.CacheMissException import com.apollographql.apollo.network.NetworkTransport -import com.apollographql.cache.normalized.ApolloStore +import com.apollographql.cache.normalized.CacheManager import com.apollographql.cache.normalized.FetchPolicy import com.apollographql.cache.normalized.api.CacheHeaders import com.apollographql.cache.normalized.api.CacheKey +import com.apollographql.cache.normalized.cacheManager import com.apollographql.cache.normalized.fetchPolicy import com.apollographql.cache.normalized.memory.MemoryCacheFactory import com.apollographql.cache.normalized.optimisticUpdates @@ -54,12 +55,12 @@ import kotlin.test.assertTrue class DeferNormalizedCacheTest { private lateinit var mockServer: MockServer private lateinit var apolloClient: ApolloClient - private lateinit var store: ApolloStore + private lateinit var cacheManager: CacheManager private suspend fun setUp() { - store = ApolloStore(MemoryCacheFactory()) + cacheManager = CacheManager(MemoryCacheFactory()) mockServer = MockServer() - apolloClient = ApolloClient.Builder().serverUrl(mockServer.url()).store(store).build() + apolloClient = ApolloClient.Builder().serverUrl(mockServer.url()).cacheManager(cacheManager).build() } private fun tearDown() { @@ -421,7 +422,7 @@ class DeferNormalizedCacheTest { ) apolloClient = ApolloClient.Builder() - .store(store) + .cacheManager(cacheManager) .fetchPolicy(FetchPolicy.NetworkFirst) .networkTransport( object : NetworkTransport { @@ -496,7 +497,7 @@ class DeferNormalizedCacheTest { assertEquals(networkExpected, networkActual) // Now cache is not empty - val cacheActual = store.readFragment(ComputerFieldsImpl(), CacheKey.MUTATION_ROOT.append("computers", "0")).data + val cacheActual = cacheManager.readFragment(ComputerFieldsImpl(), CacheKey.MUTATION_ROOT.append("computers", "0")).data println(cacheActual) // We get the last/fully formed data diff --git a/tests/garbage-collection/src/commonTest/kotlin/DanglingReferencesTest.kt b/tests/garbage-collection/src/commonTest/kotlin/DanglingReferencesTest.kt index 57e49ff6..b45fa106 100644 --- a/tests/garbage-collection/src/commonTest/kotlin/DanglingReferencesTest.kt +++ b/tests/garbage-collection/src/commonTest/kotlin/DanglingReferencesTest.kt @@ -1,10 +1,11 @@ package test import com.apollographql.apollo.ApolloClient -import com.apollographql.cache.normalized.ApolloStore +import com.apollographql.cache.normalized.CacheManager import com.apollographql.cache.normalized.FetchPolicy import com.apollographql.cache.normalized.allRecords import com.apollographql.cache.normalized.api.CacheKey +import com.apollographql.cache.normalized.cacheManager import com.apollographql.cache.normalized.fetchPolicy import com.apollographql.cache.normalized.memory.MemoryCacheFactory import com.apollographql.cache.normalized.removeDanglingReferences @@ -24,22 +25,22 @@ import kotlin.test.assertTrue class DanglingReferencesTest { @Test - fun simpleMemory() = simple(ApolloStore(MemoryCacheFactory())) + fun simpleMemory() = simple(CacheManager(MemoryCacheFactory())) @Test - fun simpleSql() = simple(ApolloStore(SqlNormalizedCacheFactory())) + fun simpleSql() = simple(CacheManager(SqlNormalizedCacheFactory())) @Test fun simpleChained(): TestResult { - return simple(ApolloStore(MemoryCacheFactory().chain(SqlNormalizedCacheFactory()))) + return simple(CacheManager(MemoryCacheFactory().chain(SqlNormalizedCacheFactory()))) } - private fun simple(apolloStore: ApolloStore) = runTest { + private fun simple(cacheManager: CacheManager) = runTest { val mockServer = MockServer() - val store = apolloStore.also { it.clearAll() } + cacheManager.clearAll() ApolloClient.Builder() .serverUrl(mockServer.url()) - .store(store) + .cacheManager(cacheManager) .build() .use { apolloClient -> mockServer.enqueueString(REPOSITORY_LIST_RESPONSE) @@ -47,11 +48,11 @@ class DanglingReferencesTest { .fetchPolicy(FetchPolicy.NetworkOnly) .execute() - var allRecords = store.accessCache { it.allRecords() } + var allRecords = cacheManager.accessCache { it.allRecords() } assertTrue(allRecords[CacheKey("Repository:0")]!!.fields.containsKey("starGazers")) // Remove User 1, now Repository 0.starGazers is a dangling reference - store.remove(CacheKey("User:1"), cascade = false) + cacheManager.remove(CacheKey("User:1"), cascade = false) val removedFieldsAndRecords = apolloClient.store.removeDanglingReferences() assertEquals( setOf(CacheKey("Repository:0").fieldKey("starGazers")), @@ -61,26 +62,26 @@ class DanglingReferencesTest { emptySet(), removedFieldsAndRecords.removedRecords ) - allRecords = store.accessCache { it.allRecords() } + allRecords = cacheManager.accessCache { it.allRecords() } assertFalse(allRecords[CacheKey("Repository:0")]!!.fields.containsKey("starGazers")) } } @Test - fun multipleMemory() = multiple(ApolloStore(MemoryCacheFactory())) + fun multipleMemory() = multiple(CacheManager(MemoryCacheFactory())) @Test - fun multipleSql() = multiple(ApolloStore(SqlNormalizedCacheFactory())) + fun multipleSql() = multiple(CacheManager(SqlNormalizedCacheFactory())) @Test - fun multipleChained() = multiple(ApolloStore(MemoryCacheFactory().chain(SqlNormalizedCacheFactory()))) + fun multipleChained() = multiple(CacheManager(MemoryCacheFactory().chain(SqlNormalizedCacheFactory()))) - private fun multiple(apolloStore: ApolloStore) = runTest { + private fun multiple(cacheManager: CacheManager) = runTest { val mockServer = MockServer() - val store = apolloStore.also { it.clearAll() } + cacheManager.clearAll() ApolloClient.Builder() .serverUrl(mockServer.url()) - .store(store) + .cacheManager(cacheManager) .build() .use { apolloClient -> mockServer.enqueueString(META_PROJECT_LIST_RESPONSE) @@ -95,7 +96,7 @@ class DanglingReferencesTest { // thus (metaProjects.0.0) is empty and removed // thus (QUERY_ROOT).metaProjects is a dangling reference // thus QUERY_ROOT is empty and removed - store.remove(CacheKey("User:0"), cascade = false) + cacheManager.remove(CacheKey("User:0"), cascade = false) val removedFieldsAndRecords = apolloClient.store.removeDanglingReferences() assertEquals( setOf( @@ -113,7 +114,7 @@ class DanglingReferencesTest { ), removedFieldsAndRecords.removedRecords ) - val allRecords = store.accessCache { it.allRecords() } + val allRecords = cacheManager.accessCache { it.allRecords() } assertFalse(allRecords.containsKey(CacheKey("QUERY_ROOT"))) assertFalse(allRecords.containsKey(CacheKey("metaProjects").append("0", "0"))) assertFalse(allRecords.containsKey(CacheKey("metaProjects").append("0", "0", "type"))) diff --git a/tests/garbage-collection/src/commonTest/kotlin/GarbageCollectTest.kt b/tests/garbage-collection/src/commonTest/kotlin/GarbageCollectTest.kt index 5548e970..badbe229 100644 --- a/tests/garbage-collection/src/commonTest/kotlin/GarbageCollectTest.kt +++ b/tests/garbage-collection/src/commonTest/kotlin/GarbageCollectTest.kt @@ -1,12 +1,13 @@ package test import com.apollographql.apollo.ApolloClient -import com.apollographql.cache.normalized.ApolloStore +import com.apollographql.cache.normalized.CacheManager import com.apollographql.cache.normalized.FetchPolicy import com.apollographql.cache.normalized.allRecords import com.apollographql.cache.normalized.api.CacheKey import com.apollographql.cache.normalized.api.SchemaCoordinatesMaxAgeProvider import com.apollographql.cache.normalized.cacheHeaders +import com.apollographql.cache.normalized.cacheManager import com.apollographql.cache.normalized.fetchPolicy import com.apollographql.cache.normalized.garbageCollect import com.apollographql.cache.normalized.memory.MemoryCacheFactory @@ -25,20 +26,20 @@ import kotlin.time.Duration.Companion.seconds class GarbageCollectTest { @Test - fun garbageCollectMemory() = garbageCollect(ApolloStore(MemoryCacheFactory())) + fun garbageCollectMemory() = garbageCollect(CacheManager(MemoryCacheFactory())) @Test - fun garbageCollectSql() = garbageCollect(ApolloStore(SqlNormalizedCacheFactory())) + fun garbageCollectSql() = garbageCollect(CacheManager(SqlNormalizedCacheFactory())) @Test - fun garbageCollectChained() = garbageCollect(ApolloStore(MemoryCacheFactory().chain(SqlNormalizedCacheFactory()))) + fun garbageCollectChained() = garbageCollect(CacheManager(MemoryCacheFactory().chain(SqlNormalizedCacheFactory()))) - private fun garbageCollect(apolloStore: ApolloStore) = runTest { + private fun garbageCollect(cacheManager: CacheManager) = runTest { val mockServer = MockServer() - val store = apolloStore.also { it.clearAll() } + cacheManager.clearAll() ApolloClient.Builder() .serverUrl(mockServer.url()) - .store(store) + .cacheManager(cacheManager) .build() .use { apolloClient -> mockServer.enqueueString(META_PROJECT_LIST_RESPONSE) @@ -104,7 +105,7 @@ class GarbageCollectTest { garbageCollectResult.removedUnreachableRecords ) - val allRecords = store.accessCache { it.allRecords() } + val allRecords = cacheManager.accessCache { it.allRecords() } assertEquals(emptyMap(), allRecords) } } diff --git a/tests/garbage-collection/src/commonTest/kotlin/ReachableCacheKeysTest.kt b/tests/garbage-collection/src/commonTest/kotlin/ReachableCacheKeysTest.kt index 38ff205a..c69fda87 100644 --- a/tests/garbage-collection/src/commonTest/kotlin/ReachableCacheKeysTest.kt +++ b/tests/garbage-collection/src/commonTest/kotlin/ReachableCacheKeysTest.kt @@ -1,10 +1,11 @@ package test import com.apollographql.apollo.ApolloClient -import com.apollographql.cache.normalized.ApolloStore +import com.apollographql.cache.normalized.CacheManager import com.apollographql.cache.normalized.FetchPolicy import com.apollographql.cache.normalized.allRecords import com.apollographql.cache.normalized.api.CacheKey +import com.apollographql.cache.normalized.cacheManager import com.apollographql.cache.normalized.fetchPolicy import com.apollographql.cache.normalized.getReachableCacheKeys import com.apollographql.cache.normalized.memory.MemoryCacheFactory @@ -23,20 +24,20 @@ import kotlin.test.assertEquals class ReachableCacheKeysTest { @Test - fun getReachableCacheKeysMemory() = getReachableCacheKeys(ApolloStore(MemoryCacheFactory())) + fun getReachableCacheKeysMemory() = getReachableCacheKeys(CacheManager(MemoryCacheFactory())) @Test - fun getReachableCacheKeysSql() = getReachableCacheKeys(ApolloStore(SqlNormalizedCacheFactory())) + fun getReachableCacheKeysSql() = getReachableCacheKeys(CacheManager(SqlNormalizedCacheFactory())) @Test - fun getReachableCacheKeysChained() = getReachableCacheKeys(ApolloStore(MemoryCacheFactory().chain(SqlNormalizedCacheFactory()))) + fun getReachableCacheKeysChained() = getReachableCacheKeys(CacheManager(MemoryCacheFactory().chain(SqlNormalizedCacheFactory()))) - private fun getReachableCacheKeys(apolloStore: ApolloStore) = runTest { + private fun getReachableCacheKeys(cacheManager: CacheManager) = runTest { val mockServer = MockServer() - val store = apolloStore.also { it.clearAll() } + cacheManager.clearAll() ApolloClient.Builder() .serverUrl(mockServer.url()) - .store(store) + .cacheManager(cacheManager) .storeReceivedDate(true) .build() .use { apolloClient -> @@ -133,7 +134,7 @@ class ReachableCacheKeysTest { ) apolloClient.query(query).fetchPolicy(FetchPolicy.NetworkOnly).execute() - var reachableCacheKeys = store.accessCache { it.allRecords().getReachableCacheKeys() } + var reachableCacheKeys = cacheManager.accessCache { it.allRecords().getReachableCacheKeys() } assertEquals( setOf( CacheKey("QUERY_ROOT"), @@ -153,8 +154,8 @@ class ReachableCacheKeysTest { ) // Remove User 43, now Repositories 5 and 6 should not be reachable / 7 should still be reachable - store.remove(CacheKey("User:43"), cascade = false) - reachableCacheKeys = store.accessCache { it.allRecords().getReachableCacheKeys() } + cacheManager.remove(CacheKey("User:43"), cascade = false) + reachableCacheKeys = cacheManager.accessCache { it.allRecords().getReachableCacheKeys() } assertEquals( setOf( CacheKey("QUERY_ROOT"), @@ -171,12 +172,12 @@ class ReachableCacheKeysTest { ) // Add a non-reachable Repository, reachableCacheKeys should not change - store.writeFragment( + cacheManager.writeFragment( RepositoryFragmentImpl(), CacheKey("Repository:500"), RepositoryFragment(id = "500", __typename = "Repository", starGazers = emptyList()), ) - reachableCacheKeys = store.accessCache { it.allRecords().getReachableCacheKeys() } + reachableCacheKeys = cacheManager.accessCache { it.allRecords().getReachableCacheKeys() } assertEquals( setOf( CacheKey("QUERY_ROOT"), @@ -206,7 +207,7 @@ class ReachableCacheKeysTest { CacheKey("Repository:500"), CacheKey("Repository:7"), ), - store.accessCache { it.allRecords() }.keys.toSet() + cacheManager.accessCache { it.allRecords() }.keys.toSet() ) // Remove unreachable records, should remove Repositories 5, 6, and 500 @@ -223,7 +224,7 @@ class ReachableCacheKeysTest { CacheKey("Repository:2"), CacheKey("Repository:1"), ), - store.accessCache { it.allRecords() }.keys.toSet() + cacheManager.accessCache { it.allRecords() }.keys.toSet() ) assertEquals( setOf( diff --git a/tests/garbage-collection/src/commonTest/kotlin/StaleFieldsTest.kt b/tests/garbage-collection/src/commonTest/kotlin/StaleFieldsTest.kt index 3d1a5bc3..4a92960a 100644 --- a/tests/garbage-collection/src/commonTest/kotlin/StaleFieldsTest.kt +++ b/tests/garbage-collection/src/commonTest/kotlin/StaleFieldsTest.kt @@ -2,7 +2,7 @@ package test import com.apollographql.apollo.ApolloClient import com.apollographql.apollo.mpp.currentTimeMillis -import com.apollographql.cache.normalized.ApolloStore +import com.apollographql.cache.normalized.CacheManager import com.apollographql.cache.normalized.FetchPolicy import com.apollographql.cache.normalized.allRecords import com.apollographql.cache.normalized.api.ApolloCacheHeaders @@ -11,6 +11,7 @@ import com.apollographql.cache.normalized.api.CacheKey import com.apollographql.cache.normalized.api.GlobalMaxAgeProvider import com.apollographql.cache.normalized.api.SchemaCoordinatesMaxAgeProvider import com.apollographql.cache.normalized.cacheHeaders +import com.apollographql.cache.normalized.cacheManager import com.apollographql.cache.normalized.fetchPolicy import com.apollographql.cache.normalized.memory.MemoryCacheFactory import com.apollographql.cache.normalized.removeStaleFields @@ -32,21 +33,21 @@ import kotlin.time.Duration.Companion.seconds class StaleFieldsTest { @Test - fun clientControlledRemoveFieldsMemory() = clientControlledRemoveFields(ApolloStore(MemoryCacheFactory())) + fun clientControlledRemoveFieldsMemory() = clientControlledRemoveFields(CacheManager(MemoryCacheFactory())) @Test - fun clientControlledRemoveFieldsSql() = clientControlledRemoveFields(ApolloStore(SqlNormalizedCacheFactory())) + fun clientControlledRemoveFieldsSql() = clientControlledRemoveFields(CacheManager(SqlNormalizedCacheFactory())) @Test fun clientControlledRemoveFieldsChained() = - clientControlledRemoveFields(ApolloStore(MemoryCacheFactory().chain(SqlNormalizedCacheFactory()))) + clientControlledRemoveFields(CacheManager(MemoryCacheFactory().chain(SqlNormalizedCacheFactory()))) - private fun clientControlledRemoveFields(apolloStore: ApolloStore) = runTest { + private fun clientControlledRemoveFields(cacheManager: CacheManager) = runTest { val mockServer = MockServer() - val store = apolloStore.also { it.clearAll() } + cacheManager.clearAll() ApolloClient.Builder() .serverUrl(mockServer.url()) - .store(store) + .cacheManager(cacheManager) .build() .use { apolloClient -> mockServer.enqueueString(REPOSITORY_LIST_RESPONSE) @@ -55,7 +56,7 @@ class StaleFieldsTest { .cacheHeaders(receivedDate(currentTimeSeconds() - 60)) .execute() - var allRecords = store.accessCache { it.allRecords() } + var allRecords = cacheManager.accessCache { it.allRecords() } assertTrue(allRecords[CacheKey("Repository:0")]!!.fields.containsKey("stars")) assertTrue(allRecords[CacheKey("Repository:0")]!!.fields.containsKey("starGazers")) assertTrue(allRecords[CacheKey("Repository:1")]!!.fields.containsKey("stars")) @@ -76,7 +77,7 @@ class StaleFieldsTest { assertEquals( emptySet(), removedFieldsAndRecords.removedRecords ) - allRecords = store.accessCache { it.allRecords() } + allRecords = cacheManager.accessCache { it.allRecords() } assertFalse(allRecords[CacheKey("Repository:0")]!!.fields.containsKey("stars")) assertTrue(allRecords[CacheKey("Repository:0")]!!.fields.containsKey("starGazers")) assertFalse(allRecords[CacheKey("Repository:1")]!!.fields.containsKey("stars")) @@ -100,7 +101,7 @@ class StaleFieldsTest { assertEquals( emptySet(), removedFieldsAndRecords.removedRecords ) - allRecords = store.accessCache { it.allRecords() } + allRecords = cacheManager.accessCache { it.allRecords() } assertFalse(allRecords[CacheKey("Repository:0")]!!.fields.containsKey("stars")) assertFalse(allRecords[CacheKey("Repository:0")]!!.fields.containsKey("starGazers")) assertFalse(allRecords[CacheKey("Repository:1")]!!.fields.containsKey("stars")) @@ -109,21 +110,21 @@ class StaleFieldsTest { } @Test - fun clientControlledRemoveRecordsMemory() = clientControlledRemoveRecords(ApolloStore(MemoryCacheFactory())) + fun clientControlledRemoveRecordsMemory() = clientControlledRemoveRecords(CacheManager(MemoryCacheFactory())) @Test - fun clientControlledRemoveRecordsSql() = clientControlledRemoveRecords(ApolloStore(SqlNormalizedCacheFactory())) + fun clientControlledRemoveRecordsSql() = clientControlledRemoveRecords(CacheManager(SqlNormalizedCacheFactory())) @Test fun clientControlledRemoveRecordsChained() = - clientControlledRemoveRecords(ApolloStore(MemoryCacheFactory().chain(SqlNormalizedCacheFactory()))) + clientControlledRemoveRecords(CacheManager(MemoryCacheFactory().chain(SqlNormalizedCacheFactory()))) - private fun clientControlledRemoveRecords(apolloStore: ApolloStore) = runTest { + private fun clientControlledRemoveRecords(cacheManager: CacheManager) = runTest { val mockServer = MockServer() - val store = apolloStore.also { it.clearAll() } + cacheManager.clearAll() ApolloClient.Builder() .serverUrl(mockServer.url()) - .store(store) + .cacheManager(cacheManager) .build() .use { apolloClient -> mockServer.enqueueString(PROJECT_LIST_RESPONSE) @@ -132,7 +133,7 @@ class StaleFieldsTest { .cacheHeaders(receivedDate(currentTimeSeconds() - 60)) .execute() - var allRecords = store.accessCache { it.allRecords() } + var allRecords = cacheManager.accessCache { it.allRecords() } assertTrue(allRecords[CacheKey("projects").append("0")]!!.fields.containsKey("velocity")) assertTrue(allRecords[CacheKey("projects").append("0")]!!.fields.containsKey("isUrgent")) assertTrue(allRecords[CacheKey("projects").append("1")]!!.fields.containsKey("velocity")) @@ -153,7 +154,7 @@ class StaleFieldsTest { assertEquals( emptySet(), removedFieldsAndRecords.removedRecords ) - allRecords = store.accessCache { it.allRecords() } + allRecords = cacheManager.accessCache { it.allRecords() } assertFalse(allRecords[CacheKey("projects").append("0")]!!.fields.containsKey("velocity")) assertTrue(allRecords[CacheKey("projects").append("0")]!!.fields.containsKey("isUrgent")) assertFalse(allRecords[CacheKey("projects").append("1")]!!.fields.containsKey("velocity")) @@ -180,28 +181,28 @@ class StaleFieldsTest { CacheKey("projects").append("1"), ), removedFieldsAndRecords.removedRecords ) - allRecords = store.accessCache { it.allRecords() } + allRecords = cacheManager.accessCache { it.allRecords() } assertFalse(allRecords.containsKey(CacheKey("projects").append("0"))) assertFalse(allRecords.containsKey(CacheKey("projects").append("1"))) } } @Test - fun serverControlledRemoveFieldsMemory() = serverControlledRemoveFields(ApolloStore(MemoryCacheFactory())) + fun serverControlledRemoveFieldsMemory() = serverControlledRemoveFields(CacheManager(MemoryCacheFactory())) @Test - fun serverControlledRemoveFieldsSql() = serverControlledRemoveFields(ApolloStore(SqlNormalizedCacheFactory())) + fun serverControlledRemoveFieldsSql() = serverControlledRemoveFields(CacheManager(SqlNormalizedCacheFactory())) @Test fun serverControlledRemoveFieldsChained() = - serverControlledRemoveFields(ApolloStore(MemoryCacheFactory().chain(SqlNormalizedCacheFactory()))) + serverControlledRemoveFields(CacheManager(MemoryCacheFactory().chain(SqlNormalizedCacheFactory()))) - private fun serverControlledRemoveFields(apolloStore: ApolloStore) = runTest { + private fun serverControlledRemoveFields(cacheManager: CacheManager) = runTest { val mockServer = MockServer() - val store = apolloStore.also { it.clearAll() } + cacheManager.clearAll() ApolloClient.Builder() .serverUrl(mockServer.url()) - .store(store) + .cacheManager(cacheManager) .build() .use { apolloClient -> mockServer.enqueueString(REPOSITORY_LIST_RESPONSE) @@ -210,7 +211,7 @@ class StaleFieldsTest { .cacheHeaders(expirationDate(currentTimeSeconds() - 60)) .execute() - var allRecords = store.accessCache { it.allRecords() } + var allRecords = cacheManager.accessCache { it.allRecords() } assertTrue(allRecords[CacheKey("Repository:0")]!!.fields.containsKey("stars")) assertTrue(allRecords[CacheKey("Repository:0")]!!.fields.containsKey("starGazers")) assertTrue(allRecords[CacheKey("Repository:1")]!!.fields.containsKey("stars")) @@ -250,7 +251,7 @@ class StaleFieldsTest { CacheKey("QUERY_ROOT"), ), removedFieldsAndRecords.removedRecords ) - allRecords = store.accessCache { it.allRecords() } + allRecords = cacheManager.accessCache { it.allRecords() } assertTrue(allRecords.isEmpty()) mockServer.enqueueString(REPOSITORY_LIST_RESPONSE) @@ -269,7 +270,7 @@ class StaleFieldsTest { emptySet(), removedFieldsAndRecords.removedRecords ) - allRecords = store.accessCache { it.allRecords() } + allRecords = cacheManager.accessCache { it.allRecords() } assertTrue(allRecords[CacheKey("Repository:0")]!!.fields.containsKey("stars")) assertTrue(allRecords[CacheKey("Repository:0")]!!.fields.containsKey("starGazers")) assertTrue(allRecords[CacheKey("Repository:1")]!!.fields.containsKey("stars")) diff --git a/tests/migration/src/commonTest/kotlin/MigrationTest.kt b/tests/migration/src/commonTest/kotlin/MigrationTest.kt index eeb6c37d..89350225 100644 --- a/tests/migration/src/commonTest/kotlin/MigrationTest.kt +++ b/tests/migration/src/commonTest/kotlin/MigrationTest.kt @@ -3,17 +3,17 @@ package test import com.apollographql.apollo.ApolloClient import com.apollographql.apollo.exception.CacheMissException import com.apollographql.apollo.mpp.currentTimeMillis -import com.apollographql.cache.normalized.ApolloStore +import com.apollographql.cache.normalized.CacheManager import com.apollographql.cache.normalized.FetchPolicy import com.apollographql.cache.normalized.api.CacheHeaders import com.apollographql.cache.normalized.api.CacheKey import com.apollographql.cache.normalized.api.DefaultRecordMerger import com.apollographql.cache.normalized.api.Record import com.apollographql.cache.normalized.api.RecordValue +import com.apollographql.cache.normalized.cacheManager import com.apollographql.cache.normalized.fetchPolicy import com.apollographql.cache.normalized.memory.MemoryCacheFactory import com.apollographql.cache.normalized.sql.SqlNormalizedCacheFactory -import com.apollographql.cache.normalized.store import com.apollographql.cache.normalized.testing.runTest import com.apollographql.mockserver.MockServer import com.apollographql.mockserver.enqueueString @@ -91,10 +91,10 @@ class MigrationTest { } // Open the legacy store which empties it. Add/read some data to make sure it works. - val store = ApolloStore(MemoryCacheFactory().chain(SqlNormalizedCacheFactory(name = name))) + val cacheManager = CacheManager(MemoryCacheFactory().chain(SqlNormalizedCacheFactory(name = name))) ApolloClient.Builder() .serverUrl(mockServer.url()) - .store(store) + .cacheManager(cacheManager) .build() .use { apolloClient -> // Expected cache miss: the db has been cleared @@ -116,7 +116,7 @@ class MigrationTest { assertEquals(REPOSITORY_LIST_DATA, response.data) // Clean up - store.clearAll() + cacheManager.clearAll() } } @@ -137,13 +137,13 @@ class MigrationTest { } // Create a modern store and migrate the legacy data - val store = ApolloStore(SqlNormalizedCacheFactory(name = "modern.db")).also { it.clearAll() } - store.migrateFrom(legacyStore) + val cacheManager = CacheManager(SqlNormalizedCacheFactory(name = "modern.db")).also { it.clearAll() } + cacheManager.migrateFrom(legacyStore) // Read the data back ApolloClient.Builder() .serverUrl(mockServer.url()) - .store(store) + .cacheManager(cacheManager) .build() .use { apolloClient -> val response = apolloClient.query(RepositoryListQuery()) @@ -154,7 +154,7 @@ class MigrationTest { } } -private fun ApolloStore.migrateFrom(legacyStore: LegacyApolloStore) { +private fun CacheManager.migrateFrom(legacyStore: LegacyApolloStore) { accessCache { cache -> cache.merge( records = legacyStore.accessCache { it.allRecords() }.map { it.toRecord() }, diff --git a/tests/models-operation-based-with-interfaces/src/commonTest/kotlin/test/BasicTest.kt b/tests/models-operation-based-with-interfaces/src/commonTest/kotlin/test/BasicTest.kt index d0596f1f..d814e66a 100644 --- a/tests/models-operation-based-with-interfaces/src/commonTest/kotlin/test/BasicTest.kt +++ b/tests/models-operation-based-with-interfaces/src/commonTest/kotlin/test/BasicTest.kt @@ -7,12 +7,12 @@ import com.apollographql.apollo.ApolloClient import com.apollographql.apollo.api.ApolloResponse import com.apollographql.apollo.api.Optional import com.apollographql.apollo.api.Query -import com.apollographql.cache.normalized.ApolloStore +import com.apollographql.cache.normalized.CacheManager import com.apollographql.cache.normalized.FetchPolicy import com.apollographql.cache.normalized.api.IdCacheKeyGenerator +import com.apollographql.cache.normalized.cacheManager import com.apollographql.cache.normalized.fetchPolicy import com.apollographql.cache.normalized.memory.MemoryCacheFactory -import com.apollographql.cache.normalized.store import com.apollographql.cache.normalized.testing.runTest import com.apollographql.mockserver.MockServer import com.apollographql.mockserver.enqueueString @@ -25,15 +25,15 @@ import kotlin.test.assertTrue class BasicTest { private lateinit var mockServer: MockServer private lateinit var apolloClient: ApolloClient - private lateinit var store: ApolloStore + private lateinit var cacheManager: CacheManager private suspend fun setUp() { - store = ApolloStore( + cacheManager = CacheManager( normalizedCacheFactory = MemoryCacheFactory(), cacheKeyGenerator = IdCacheKeyGenerator() ) mockServer = MockServer() - apolloClient = ApolloClient.Builder().serverUrl(mockServer.url()).store(store).build() + apolloClient = ApolloClient.Builder().serverUrl(mockServer.url()).cacheManager(cacheManager).build() } private suspend fun tearDown() { diff --git a/tests/models-operation-based-with-interfaces/src/commonTest/kotlin/test/StoreTest.kt b/tests/models-operation-based-with-interfaces/src/commonTest/kotlin/test/StoreTest.kt index b1072ac0..24cdff90 100644 --- a/tests/models-operation-based-with-interfaces/src/commonTest/kotlin/test/StoreTest.kt +++ b/tests/models-operation-based-with-interfaces/src/commonTest/kotlin/test/StoreTest.kt @@ -7,11 +7,11 @@ import codegen.models.fragment.HeroWithFriendsFragmentImpl import codegen.models.fragment.HumanWithIdFragment import codegen.models.fragment.HumanWithIdFragmentImpl import com.apollographql.apollo.ApolloClient -import com.apollographql.cache.normalized.ApolloStore +import com.apollographql.cache.normalized.CacheManager import com.apollographql.cache.normalized.api.CacheKey import com.apollographql.cache.normalized.api.IdCacheKeyGenerator +import com.apollographql.cache.normalized.cacheManager import com.apollographql.cache.normalized.memory.MemoryCacheFactory -import com.apollographql.cache.normalized.store import com.apollographql.cache.normalized.testing.runTest import com.apollographql.mockserver.MockServer import com.apollographql.mockserver.enqueueString @@ -22,15 +22,15 @@ import kotlin.test.assertEquals class StoreTest { private lateinit var mockServer: MockServer private lateinit var apolloClient: ApolloClient - private lateinit var store: ApolloStore + private lateinit var cacheManager: CacheManager private suspend fun setUp() { - store = ApolloStore( + cacheManager = CacheManager( normalizedCacheFactory = MemoryCacheFactory(), cacheKeyGenerator = IdCacheKeyGenerator() ) mockServer = MockServer() - apolloClient = ApolloClient.Builder().serverUrl(mockServer.url()).store(store).build() + apolloClient = ApolloClient.Builder().serverUrl(mockServer.url()).cacheManager(cacheManager).build() } private suspend fun tearDown() { @@ -42,7 +42,7 @@ class StoreTest { mockServer.enqueueString(testFixtureToUtf8("HeroAndFriendsWithTypename.json")) apolloClient.query(HeroAndFriendsWithTypenameQuery()).execute() - val heroWithFriendsFragment = store.readFragment( + val heroWithFriendsFragment = cacheManager.readFragment( HeroWithFriendsFragmentImpl(), CacheKey("Character:2001"), ).data @@ -56,7 +56,7 @@ class StoreTest { assertEquals(heroWithFriendsFragment.friends?.get(2)?.humanWithIdFragment?.id, "1003") assertEquals(heroWithFriendsFragment.friends?.get(2)?.humanWithIdFragment?.name, "Leia Organa") - var fragment = store.readFragment( + var fragment = cacheManager.readFragment( HumanWithIdFragmentImpl(), CacheKey("Character:1000"), ).data @@ -64,14 +64,14 @@ class StoreTest { assertEquals(fragment.id, "1000") assertEquals(fragment.name, "Luke Skywalker") - fragment = store.readFragment( + fragment = cacheManager.readFragment( HumanWithIdFragmentImpl(), CacheKey("Character:1002"), ).data assertEquals(fragment.id, "1002") assertEquals(fragment.name, "Han Solo") - fragment = store.readFragment( + fragment = cacheManager.readFragment( HumanWithIdFragmentImpl(), CacheKey("Character:1003"), ).data @@ -98,7 +98,7 @@ class StoreTest { assertEquals(response.data?.hero?.heroWithFriendsFragment?.friends?.get(2)?.humanWithIdFragment?.id, "1003") assertEquals(response.data?.hero?.heroWithFriendsFragment?.friends?.get(2)?.humanWithIdFragment?.name, "Leia Organa") - store.writeFragment( + cacheManager.writeFragment( HeroWithFriendsFragmentImpl(), CacheKey("Character:2001"), HeroWithFriendsFragment( @@ -123,7 +123,7 @@ class StoreTest { ), ) - store.writeFragment( + cacheManager.writeFragment( HumanWithIdFragmentImpl(), CacheKey("Character:1002"), HumanWithIdFragment( diff --git a/tests/models-operation-based/src/commonTest/kotlin/test/BasicTest.kt b/tests/models-operation-based/src/commonTest/kotlin/test/BasicTest.kt index d0596f1f..d814e66a 100644 --- a/tests/models-operation-based/src/commonTest/kotlin/test/BasicTest.kt +++ b/tests/models-operation-based/src/commonTest/kotlin/test/BasicTest.kt @@ -7,12 +7,12 @@ import com.apollographql.apollo.ApolloClient import com.apollographql.apollo.api.ApolloResponse import com.apollographql.apollo.api.Optional import com.apollographql.apollo.api.Query -import com.apollographql.cache.normalized.ApolloStore +import com.apollographql.cache.normalized.CacheManager import com.apollographql.cache.normalized.FetchPolicy import com.apollographql.cache.normalized.api.IdCacheKeyGenerator +import com.apollographql.cache.normalized.cacheManager import com.apollographql.cache.normalized.fetchPolicy import com.apollographql.cache.normalized.memory.MemoryCacheFactory -import com.apollographql.cache.normalized.store import com.apollographql.cache.normalized.testing.runTest import com.apollographql.mockserver.MockServer import com.apollographql.mockserver.enqueueString @@ -25,15 +25,15 @@ import kotlin.test.assertTrue class BasicTest { private lateinit var mockServer: MockServer private lateinit var apolloClient: ApolloClient - private lateinit var store: ApolloStore + private lateinit var cacheManager: CacheManager private suspend fun setUp() { - store = ApolloStore( + cacheManager = CacheManager( normalizedCacheFactory = MemoryCacheFactory(), cacheKeyGenerator = IdCacheKeyGenerator() ) mockServer = MockServer() - apolloClient = ApolloClient.Builder().serverUrl(mockServer.url()).store(store).build() + apolloClient = ApolloClient.Builder().serverUrl(mockServer.url()).cacheManager(cacheManager).build() } private suspend fun tearDown() { diff --git a/tests/models-operation-based/src/commonTest/kotlin/test/StoreTest.kt b/tests/models-operation-based/src/commonTest/kotlin/test/StoreTest.kt index a2f0ade8..6f5997ef 100644 --- a/tests/models-operation-based/src/commonTest/kotlin/test/StoreTest.kt +++ b/tests/models-operation-based/src/commonTest/kotlin/test/StoreTest.kt @@ -7,11 +7,11 @@ import codegen.models.fragment.HeroWithFriendsFragmentImpl import codegen.models.fragment.HumanWithIdFragment import codegen.models.fragment.HumanWithIdFragmentImpl import com.apollographql.apollo.ApolloClient -import com.apollographql.cache.normalized.ApolloStore +import com.apollographql.cache.normalized.CacheManager import com.apollographql.cache.normalized.api.CacheKey import com.apollographql.cache.normalized.api.IdCacheKeyGenerator +import com.apollographql.cache.normalized.cacheManager import com.apollographql.cache.normalized.memory.MemoryCacheFactory -import com.apollographql.cache.normalized.store import com.apollographql.cache.normalized.testing.runTest import com.apollographql.mockserver.MockServer import com.apollographql.mockserver.enqueueString @@ -22,15 +22,15 @@ import kotlin.test.assertEquals class StoreTest { private lateinit var mockServer: MockServer private lateinit var apolloClient: ApolloClient - private lateinit var store: ApolloStore + private lateinit var cacheManager: CacheManager private suspend fun setUp() { - store = ApolloStore( + cacheManager = CacheManager( normalizedCacheFactory = MemoryCacheFactory(), cacheKeyGenerator = IdCacheKeyGenerator() ) mockServer = MockServer() - apolloClient = ApolloClient.Builder().serverUrl(mockServer.url()).store(store).build() + apolloClient = ApolloClient.Builder().serverUrl(mockServer.url()).cacheManager(cacheManager).build() } private suspend fun tearDown() { @@ -42,7 +42,7 @@ class StoreTest { mockServer.enqueueString(testFixtureToUtf8("HeroAndFriendsWithTypename.json")) apolloClient.query(HeroAndFriendsWithTypenameQuery()).execute() - val heroWithFriendsFragment = store.readFragment( + val heroWithFriendsFragment = cacheManager.readFragment( HeroWithFriendsFragmentImpl(), CacheKey("Character:2001"), ).data @@ -56,7 +56,7 @@ class StoreTest { assertEquals(heroWithFriendsFragment.friends?.get(2)?.humanWithIdFragment?.id, "1003") assertEquals(heroWithFriendsFragment.friends?.get(2)?.humanWithIdFragment?.name, "Leia Organa") - var fragment = store.readFragment( + var fragment = cacheManager.readFragment( HumanWithIdFragmentImpl(), CacheKey("Character:1000"), ).data @@ -64,14 +64,14 @@ class StoreTest { assertEquals(fragment.id, "1000") assertEquals(fragment.name, "Luke Skywalker") - fragment = store.readFragment( + fragment = cacheManager.readFragment( HumanWithIdFragmentImpl(), CacheKey("Character:1002"), ).data assertEquals(fragment.id, "1002") assertEquals(fragment.name, "Han Solo") - fragment = store.readFragment( + fragment = cacheManager.readFragment( HumanWithIdFragmentImpl(), CacheKey("Character:1003"), ).data @@ -98,7 +98,7 @@ class StoreTest { assertEquals(response.data?.hero?.heroWithFriendsFragment?.friends?.get(2)?.humanWithIdFragment?.id, "1003") assertEquals(response.data?.hero?.heroWithFriendsFragment?.friends?.get(2)?.humanWithIdFragment?.name, "Leia Organa") - store.writeFragment( + cacheManager.writeFragment( HeroWithFriendsFragmentImpl(), CacheKey("Character:2001"), HeroWithFriendsFragment( @@ -123,7 +123,7 @@ class StoreTest { ), ) - store.writeFragment( + cacheManager.writeFragment( HumanWithIdFragmentImpl(), CacheKey("Character:1002"), HumanWithIdFragment( diff --git a/tests/models-response-based/src/commonTest/kotlin/test/BasicTest.kt b/tests/models-response-based/src/commonTest/kotlin/test/BasicTest.kt index ed9b252f..18a02df7 100644 --- a/tests/models-response-based/src/commonTest/kotlin/test/BasicTest.kt +++ b/tests/models-response-based/src/commonTest/kotlin/test/BasicTest.kt @@ -12,12 +12,12 @@ import com.apollographql.apollo.ApolloClient import com.apollographql.apollo.api.ApolloResponse import com.apollographql.apollo.api.Optional import com.apollographql.apollo.api.Query -import com.apollographql.cache.normalized.ApolloStore +import com.apollographql.cache.normalized.CacheManager import com.apollographql.cache.normalized.FetchPolicy import com.apollographql.cache.normalized.api.IdCacheKeyGenerator +import com.apollographql.cache.normalized.cacheManager import com.apollographql.cache.normalized.fetchPolicy import com.apollographql.cache.normalized.memory.MemoryCacheFactory -import com.apollographql.cache.normalized.store import com.apollographql.cache.normalized.testing.runTest import com.apollographql.mockserver.MockServer import com.apollographql.mockserver.enqueueString @@ -30,15 +30,15 @@ import kotlin.test.assertTrue class BasicTest { private lateinit var mockServer: MockServer private lateinit var apolloClient: ApolloClient - private lateinit var store: ApolloStore + private lateinit var cacheManager: CacheManager private suspend fun setUp() { - store = ApolloStore( + cacheManager = CacheManager( normalizedCacheFactory = MemoryCacheFactory(), cacheKeyGenerator = IdCacheKeyGenerator() ) mockServer = MockServer() - apolloClient = ApolloClient.Builder().serverUrl(mockServer.url()).store(store).build() + apolloClient = ApolloClient.Builder().serverUrl(mockServer.url()).cacheManager(cacheManager).build() } private suspend fun tearDown() { diff --git a/tests/models-response-based/src/commonTest/kotlin/test/StoreTest.kt b/tests/models-response-based/src/commonTest/kotlin/test/StoreTest.kt index 917b9bb3..ff444562 100644 --- a/tests/models-response-based/src/commonTest/kotlin/test/StoreTest.kt +++ b/tests/models-response-based/src/commonTest/kotlin/test/StoreTest.kt @@ -8,11 +8,11 @@ import codegen.models.fragment.HeroWithFriendsFragment.Friend.Companion.humanWit import codegen.models.fragment.HeroWithFriendsFragmentImpl import codegen.models.fragment.HumanWithIdFragmentImpl import com.apollographql.apollo.ApolloClient -import com.apollographql.cache.normalized.ApolloStore +import com.apollographql.cache.normalized.CacheManager import com.apollographql.cache.normalized.api.CacheKey import com.apollographql.cache.normalized.api.IdCacheKeyGenerator +import com.apollographql.cache.normalized.cacheManager import com.apollographql.cache.normalized.memory.MemoryCacheFactory -import com.apollographql.cache.normalized.store import com.apollographql.cache.normalized.testing.runTest import com.apollographql.mockserver.MockServer import com.apollographql.mockserver.enqueueString @@ -23,15 +23,15 @@ import kotlin.test.assertEquals class StoreTest { private lateinit var mockServer: MockServer private lateinit var apolloClient: ApolloClient - private lateinit var store: ApolloStore + private lateinit var cacheManager: CacheManager private suspend fun setUp() { - store = ApolloStore( + cacheManager = CacheManager( normalizedCacheFactory = MemoryCacheFactory(), cacheKeyGenerator = IdCacheKeyGenerator() ) mockServer = MockServer() - apolloClient = ApolloClient.Builder().serverUrl(mockServer.url()).store(store).build() + apolloClient = ApolloClient.Builder().serverUrl(mockServer.url()).cacheManager(cacheManager).build() } private suspend fun tearDown() { @@ -43,7 +43,7 @@ class StoreTest { mockServer.enqueueString(testFixtureToUtf8("HeroAndFriendsWithTypename.json")) apolloClient.query(HeroAndFriendsWithTypenameQuery()).execute() - val heroWithFriendsFragment = store.readFragment( + val heroWithFriendsFragment = cacheManager.readFragment( HeroWithFriendsFragmentImpl(), CacheKey("Character:2001"), ).data @@ -57,7 +57,7 @@ class StoreTest { assertEquals(heroWithFriendsFragment.friends?.get(2)?.asHuman()?.id, "1003") assertEquals(heroWithFriendsFragment.friends?.get(2)?.asHuman()?.name, "Leia Organa") - var fragment = store.readFragment( + var fragment = cacheManager.readFragment( HumanWithIdFragmentImpl(), CacheKey("Character:1000"), ).data @@ -65,14 +65,14 @@ class StoreTest { assertEquals(fragment.id, "1000") assertEquals(fragment.name, "Luke Skywalker") - fragment = store.readFragment( + fragment = cacheManager.readFragment( HumanWithIdFragmentImpl(), CacheKey("Character:1002"), ).data assertEquals(fragment.id, "1002") assertEquals(fragment.name, "Han Solo") - fragment = store.readFragment( + fragment = cacheManager.readFragment( HumanWithIdFragmentImpl(), CacheKey("Character:1003"), ).data @@ -99,7 +99,7 @@ class StoreTest { assertEquals(response.data?.hero?.heroWithFriendsFragment()?.friends?.get(2)?.humanWithIdFragment()?.id, "1003") assertEquals(response.data?.hero?.heroWithFriendsFragment()?.friends?.get(2)?.humanWithIdFragment()?.name, "Leia Organa") - store.writeFragment( + cacheManager.writeFragment( HeroWithFriendsFragmentImpl(), CacheKey("Character:2001"), HeroWithFriendsFragmentImpl.Data( @@ -120,7 +120,7 @@ class StoreTest { ), ) - store.writeFragment( + cacheManager.writeFragment( HumanWithIdFragmentImpl(), CacheKey("Character:1002"), HumanWithIdFragmentImpl.Data( diff --git a/tests/normalization-tests/src/commonTest/kotlin/com/example/NormalizationTest.kt b/tests/normalization-tests/src/commonTest/kotlin/com/example/NormalizationTest.kt index 3272c1a3..c3951e9b 100644 --- a/tests/normalization-tests/src/commonTest/kotlin/com/example/NormalizationTest.kt +++ b/tests/normalization-tests/src/commonTest/kotlin/com/example/NormalizationTest.kt @@ -4,7 +4,7 @@ import com.apollographql.apollo.ApolloClient import com.apollographql.apollo.api.CustomScalarAdapters import com.apollographql.apollo.api.json.jsonReader import com.apollographql.apollo.api.toApolloResponse -import com.apollographql.cache.normalized.ApolloStore +import com.apollographql.cache.normalized.CacheManager import com.apollographql.cache.normalized.FetchPolicy import com.apollographql.cache.normalized.api.CacheKey import com.apollographql.cache.normalized.api.CacheKeyGenerator @@ -14,10 +14,10 @@ import com.apollographql.cache.normalized.api.CacheResolver import com.apollographql.cache.normalized.api.FieldPolicyCacheResolver import com.apollographql.cache.normalized.api.ResolverContext import com.apollographql.cache.normalized.api.TypePolicyCacheKeyGenerator +import com.apollographql.cache.normalized.cacheManager import com.apollographql.cache.normalized.fetchPolicy import com.apollographql.cache.normalized.memory.MemoryCacheFactory import com.apollographql.cache.normalized.normalizedCache -import com.apollographql.cache.normalized.store import com.apollographql.cache.normalized.testing.runTest import com.apollographql.mockserver.MockServer import com.apollographql.mockserver.enqueueString @@ -50,7 +50,7 @@ internal object IdBasedCacheKeyResolver : CacheResolver, CacheKeyGenerator { class NormalizationTest { @Test fun issue3672() = runTest { - val store = ApolloStore( + val store = CacheManager( normalizedCacheFactory = MemoryCacheFactory(), cacheKeyGenerator = IdBasedCacheKeyResolver, cacheResolver = IdBasedCacheKeyResolver @@ -69,7 +69,7 @@ class NormalizationTest { @Test fun issue3672_2() = runTest { - val store = ApolloStore( + val store = CacheManager( normalizedCacheFactory = MemoryCacheFactory(), cacheKeyGenerator = IdBasedCacheKeyResolver, cacheResolver = IdBasedCacheKeyResolver @@ -87,13 +87,13 @@ class NormalizationTest { @Test fun issue2818() = runTest { - val apolloStore = ApolloStore( + val cacheManager = CacheManager( normalizedCacheFactory = MemoryCacheFactory(), cacheKeyGenerator = IdBasedCacheKeyResolver, cacheResolver = IdBasedCacheKeyResolver ) - apolloStore.writeOperation( + cacheManager.writeOperation( Issue2818Query(), Issue2818Query.Data( Issue2818Query.Home( @@ -111,7 +111,7 @@ class NormalizationTest { ), ) - val data = apolloStore.readOperation(Issue2818Query()).data!! + val data = cacheManager.readOperation(Issue2818Query()).data!! assertEquals("section-name", data.home.sectionA?.name) assertEquals("section-id", data.home.sectionFragment.sectionA?.id) assertEquals("https://...", data.home.sectionFragment.sectionA?.imageUrl) @@ -148,8 +148,8 @@ class NormalizationTest { val mockserver = MockServer() val apolloClient = ApolloClient.Builder() .serverUrl(mockserver.url()) - .store( - ApolloStore( + .cacheManager( + CacheManager( normalizedCacheFactory = MemoryCacheFactory(), cacheKeyGenerator = TypePolicyCacheKeyGenerator, cacheResolver = object : CacheKeyResolver() { @@ -222,8 +222,8 @@ class NormalizationTest { val mockserver = MockServer() val apolloClient = ApolloClient.Builder() .serverUrl(mockserver.url()) - .store( - ApolloStore( + .cacheManager( + CacheManager( normalizedCacheFactory = MemoryCacheFactory(), cacheKeyGenerator = TypePolicyCacheKeyGenerator, cacheResolver = object : CacheResolver { @@ -295,7 +295,7 @@ class NormalizationTest { // Fetch from network apolloClient.query(GetBooksByIdsPaginatedQuery(listOf("book-1", "book-2"))).fetchPolicy(FetchPolicy.NetworkOnly).execute() - // println(NormalizedCache.prettifyDump(apolloClient.apolloStore.dump())) + // println(NormalizedCache.prettifyDump(apolloClient.cacheManager.dump())) // Fetch from the cache val fromCache1 = apolloClient.query(GetBooksByIdsPaginatedNoCursorsQuery(listOf("book-1"))).fetchPolicy(FetchPolicy.CacheOnly).execute() diff --git a/tests/normalization-tests/src/concurrentTest/kotlin/com/example/SqlNormalizationTest.kt b/tests/normalization-tests/src/concurrentTest/kotlin/com/example/SqlNormalizationTest.kt index 72a5d1b6..22885bfb 100644 --- a/tests/normalization-tests/src/concurrentTest/kotlin/com/example/SqlNormalizationTest.kt +++ b/tests/normalization-tests/src/concurrentTest/kotlin/com/example/SqlNormalizationTest.kt @@ -4,10 +4,10 @@ import com.apollographql.apollo.ApolloClient import com.apollographql.cache.normalized.FetchPolicy import com.apollographql.cache.normalized.allRecords import com.apollographql.cache.normalized.api.CacheKey -import com.apollographql.cache.normalized.apolloStore import com.apollographql.cache.normalized.fetchPolicy import com.apollographql.cache.normalized.normalizedCache import com.apollographql.cache.normalized.sql.SqlNormalizedCacheFactory +import com.apollographql.cache.normalized.store import com.apollographql.cache.normalized.testing.append import com.apollographql.cache.normalized.testing.runTest import com.apollographql.mockserver.MockServer @@ -25,7 +25,7 @@ class SqlNormalizationTest { .normalizedCache(SqlNormalizedCacheFactory()) .build() - apolloClient.apolloStore.clearAll() + apolloClient.store.clearAll() mockserver.enqueueString( // language=JSON """ @@ -55,7 +55,7 @@ class SqlNormalizationTest { ) apolloClient.mutation(CreateUserMutation("John")).fetchPolicy(FetchPolicy.NetworkOnly).execute() - apolloClient.apolloStore.accessCache { normalizedCache -> + apolloClient.store.accessCache { normalizedCache -> assertContentEquals( listOf( CacheKey.MUTATION_ROOT, diff --git a/tests/normalized-cache/src/commonTest/kotlin/BasicTest.kt b/tests/normalized-cache/src/commonTest/kotlin/BasicTest.kt index 4cfc164d..a14bcab3 100644 --- a/tests/normalized-cache/src/commonTest/kotlin/BasicTest.kt +++ b/tests/normalized-cache/src/commonTest/kotlin/BasicTest.kt @@ -3,12 +3,12 @@ package test import com.apollographql.apollo.ApolloClient import com.apollographql.apollo.api.ApolloResponse import com.apollographql.apollo.api.Query -import com.apollographql.cache.normalized.ApolloStore +import com.apollographql.cache.normalized.CacheManager import com.apollographql.cache.normalized.FetchPolicy import com.apollographql.cache.normalized.api.IdCacheKeyGenerator +import com.apollographql.cache.normalized.cacheManager import com.apollographql.cache.normalized.fetchPolicy import com.apollographql.cache.normalized.memory.MemoryCacheFactory -import com.apollographql.cache.normalized.store import com.apollographql.cache.normalized.testing.runTest import com.apollographql.mockserver.MockServer import com.apollographql.mockserver.enqueueString @@ -36,15 +36,15 @@ import kotlin.test.assertNull class BasicTest { private lateinit var mockServer: MockServer private lateinit var apolloClient: ApolloClient - private lateinit var store: ApolloStore + private lateinit var cacheManager: CacheManager private suspend fun setUp() { - store = ApolloStore( + cacheManager = CacheManager( normalizedCacheFactory = MemoryCacheFactory(), cacheKeyGenerator = IdCacheKeyGenerator() ) mockServer = MockServer() - apolloClient = ApolloClient.Builder().serverUrl(mockServer.url()).store(store).build() + apolloClient = ApolloClient.Builder().serverUrl(mockServer.url()).cacheManager(cacheManager).build() } private suspend fun tearDown() { diff --git a/tests/normalized-cache/src/commonTest/kotlin/CacheFlagsTest.kt b/tests/normalized-cache/src/commonTest/kotlin/CacheFlagsTest.kt index f3dc8800..c8923d9d 100644 --- a/tests/normalized-cache/src/commonTest/kotlin/CacheFlagsTest.kt +++ b/tests/normalized-cache/src/commonTest/kotlin/CacheFlagsTest.kt @@ -9,15 +9,15 @@ import com.apollographql.apollo.exception.CacheMissException import com.apollographql.apollo.network.NetworkTransport import com.apollographql.apollo.testing.QueueTestNetworkTransport import com.apollographql.apollo.testing.enqueueTestResponse -import com.apollographql.cache.normalized.ApolloStore +import com.apollographql.cache.normalized.CacheManager import com.apollographql.cache.normalized.FetchPolicy import com.apollographql.cache.normalized.api.ApolloCacheHeaders import com.apollographql.cache.normalized.api.CacheHeaders import com.apollographql.cache.normalized.cacheHeaders +import com.apollographql.cache.normalized.cacheManager import com.apollographql.cache.normalized.doNotStore import com.apollographql.cache.normalized.fetchPolicy import com.apollographql.cache.normalized.memory.MemoryCacheFactory -import com.apollographql.cache.normalized.store import com.apollographql.cache.normalized.testing.runTest import com.benasher44.uuid.uuid4 import kotlinx.coroutines.flow.Flow @@ -29,11 +29,11 @@ import kotlin.test.assertNotNull class CacheFlagsTest { private lateinit var apolloClient: ApolloClient - private lateinit var store: ApolloStore + private lateinit var cacheManager: CacheManager private fun setUp() { - store = ApolloStore(MemoryCacheFactory()) - apolloClient = ApolloClient.Builder().networkTransport(QueueTestNetworkTransport()).store(store).build() + cacheManager = CacheManager(MemoryCacheFactory()) + apolloClient = ApolloClient.Builder().networkTransport(QueueTestNetworkTransport()).cacheManager(cacheManager).build() } @Test @@ -75,10 +75,10 @@ class CacheFlagsTest { val query = HeroNameQuery() val data = HeroNameQuery.Data(HeroNameQuery.Hero("R2-D2")) - store = ApolloStore(MemoryCacheFactory()) + cacheManager = CacheManager(MemoryCacheFactory()) val queueTestNetworkTransport = QueueTestNetworkTransport() apolloClient = ApolloClient.Builder() - .store(store) + .cacheManager(cacheManager) .networkTransport(object : NetworkTransport { val delegate = queueTestNetworkTransport override fun execute(request: ApolloRequest): Flow> { diff --git a/tests/normalized-cache/src/commonTest/kotlin/CacheResolverTest.kt b/tests/normalized-cache/src/commonTest/kotlin/CacheResolverTest.kt index b000da08..897b2b2f 100644 --- a/tests/normalized-cache/src/commonTest/kotlin/CacheResolverTest.kt +++ b/tests/normalized-cache/src/commonTest/kotlin/CacheResolverTest.kt @@ -1,12 +1,12 @@ package test import com.apollographql.apollo.ApolloClient -import com.apollographql.cache.normalized.ApolloStore +import com.apollographql.cache.normalized.CacheManager import com.apollographql.cache.normalized.api.CacheResolver import com.apollographql.cache.normalized.api.DefaultCacheResolver import com.apollographql.cache.normalized.api.ResolverContext +import com.apollographql.cache.normalized.cacheManager import com.apollographql.cache.normalized.memory.MemoryCacheFactory -import com.apollographql.cache.normalized.store import com.apollographql.cache.normalized.testing.runTest import normalizer.HeroNameQuery import kotlin.test.Test @@ -24,8 +24,8 @@ class CacheResolverTest { } } val apolloClient = ApolloClient.Builder().serverUrl(serverUrl = "") - .store( - ApolloStore( + .cacheManager( + CacheManager( normalizedCacheFactory = MemoryCacheFactory(), cacheResolver = resolver ) diff --git a/tests/normalized-cache/src/commonTest/kotlin/FetchPolicyTest.kt b/tests/normalized-cache/src/commonTest/kotlin/FetchPolicyTest.kt index d7931b97..f2b0d8c3 100644 --- a/tests/normalized-cache/src/commonTest/kotlin/FetchPolicyTest.kt +++ b/tests/normalized-cache/src/commonTest/kotlin/FetchPolicyTest.kt @@ -18,16 +18,16 @@ import com.apollographql.apollo.exception.CacheMissException import com.apollographql.apollo.exception.JsonEncodingException import com.apollographql.apollo.interceptor.ApolloInterceptor import com.apollographql.apollo.interceptor.ApolloInterceptorChain -import com.apollographql.cache.normalized.ApolloStore import com.apollographql.cache.normalized.CacheFirstInterceptor +import com.apollographql.cache.normalized.CacheManager import com.apollographql.cache.normalized.CacheOnlyInterceptor import com.apollographql.cache.normalized.FetchPolicy import com.apollographql.cache.normalized.api.CacheKey +import com.apollographql.cache.normalized.cacheManager import com.apollographql.cache.normalized.fetchPolicy import com.apollographql.cache.normalized.isFromCache import com.apollographql.cache.normalized.memory.MemoryCacheFactory import com.apollographql.cache.normalized.refetchPolicyInterceptor -import com.apollographql.cache.normalized.store import com.apollographql.cache.normalized.testing.assertNoElement import com.apollographql.cache.normalized.testing.fieldKey import com.apollographql.cache.normalized.testing.runTest @@ -58,12 +58,12 @@ import kotlin.test.fail class FetchPolicyTest { private lateinit var mockServer: MockServer private lateinit var apolloClient: ApolloClient - private lateinit var store: ApolloStore + private lateinit var cacheManager: CacheManager private suspend fun setUp() { - store = ApolloStore(MemoryCacheFactory()) + cacheManager = CacheManager(MemoryCacheFactory()) mockServer = MockServer() - apolloClient = ApolloClient.Builder().serverUrl(mockServer.url()).store(store = store).build() + apolloClient = ApolloClient.Builder().serverUrl(mockServer.url()).cacheManager(cacheManager = cacheManager).build() } private fun tearDown() { @@ -92,7 +92,7 @@ class FetchPolicyTest { assertTrue(response.isFromCache) // Clear the store and offer a malformed response, we should get a composite error - store.clearAll() + cacheManager.clearAll() mockServer.enqueueString("malformed") apolloClient.query(query).execute().exception.let { assertIs(it) @@ -125,7 +125,7 @@ class FetchPolicyTest { assertTrue(response.isFromCache) // Clear the store and offer a malformed response, we should get a composite error - store.clearAll() + cacheManager.clearAll() mockServer.enqueueString("malformed") try { @Suppress("DEPRECATION") @@ -173,7 +173,7 @@ class FetchPolicyTest { } // Clear the store and offer a malformed response, we should get a composite error - store.clearAll() + cacheManager.clearAll() mockServer.enqueueString("malformed") @Suppress("DEPRECATION") responses = apolloClient.query(query) @@ -215,7 +215,7 @@ class FetchPolicyTest { // Network error and no cache -> we should get an error mockServer.enqueueString("malformed") - store.clearAll() + cacheManager.clearAll() call.execute().exception.let { assertIs(it) @@ -254,7 +254,7 @@ class FetchPolicyTest { // Network error and no cache -> we should get an error mockServer.enqueueString("malformed") - store.clearAll() + cacheManager.clearAll() try { @Suppress("DEPRECATION") call.executeV3() @@ -308,7 +308,7 @@ class FetchPolicyTest { // Network error and no cache -> we should get an error mockServer.enqueueString("malformed") - store.clearAll() + cacheManager.clearAll() @Suppress("DEPRECATION") responses = call.toFlowV3() responses.test { @@ -589,7 +589,7 @@ class FetchPolicyTest { /** * clear the cache and trigger the watcher again */ - store.clearAll() + cacheManager.clearAll() mockServer.enqueueString( buildJsonString { @@ -603,7 +603,7 @@ class FetchPolicyTest { ) } ) - store.publish(setOf(CacheKey.QUERY_ROOT.fieldKey("hero"))) + cacheManager.publish(setOf(CacheKey.QUERY_ROOT.fieldKey("hero"))) /** * This time the watcher should do a network request @@ -644,7 +644,7 @@ class FetchPolicyTest { assertTrue(response.isFromCache) // CacheOnly / miss - store.clearAll() + cacheManager.clearAll() response = apolloClient.query(query) .fetchPolicy(FetchPolicy.CacheOnly) .execute() @@ -660,7 +660,7 @@ class FetchPolicyTest { assertFalse(response.isFromCache) // CacheFirst / miss / miss - store.clearAll() + cacheManager.clearAll() mockServer.enqueueString("malformed") var responses = apolloClient.query(query) .fetchPolicy(FetchPolicy.CacheFirst) @@ -670,7 +670,7 @@ class FetchPolicyTest { assertFalse(responses[1].isFromCache) // NetworkFirst / miss / miss - store.clearAll() + cacheManager.clearAll() mockServer.enqueueString("malformed") responses = apolloClient.query(query) .fetchPolicy(FetchPolicy.NetworkFirst) diff --git a/tests/normalized-cache/src/commonTest/kotlin/IdCacheKeyGeneratorTest.kt b/tests/normalized-cache/src/commonTest/kotlin/IdCacheKeyGeneratorTest.kt index 31ec420e..682cdf75 100644 --- a/tests/normalized-cache/src/commonTest/kotlin/IdCacheKeyGeneratorTest.kt +++ b/tests/normalized-cache/src/commonTest/kotlin/IdCacheKeyGeneratorTest.kt @@ -3,13 +3,13 @@ package test import com.apollographql.apollo.ApolloClient import com.apollographql.apollo.testing.QueueTestNetworkTransport import com.apollographql.apollo.testing.enqueueTestResponse -import com.apollographql.cache.normalized.ApolloStore +import com.apollographql.cache.normalized.CacheManager import com.apollographql.cache.normalized.FetchPolicy import com.apollographql.cache.normalized.api.IdCacheKeyGenerator import com.apollographql.cache.normalized.api.IdCacheKeyResolver +import com.apollographql.cache.normalized.cacheManager import com.apollographql.cache.normalized.fetchPolicy import com.apollographql.cache.normalized.memory.MemoryCacheFactory -import com.apollographql.cache.normalized.store import com.apollographql.cache.normalized.testing.runTest import main.GetUser2Query import main.GetUserByIdQuery @@ -21,12 +21,12 @@ import kotlin.test.assertEquals class IdCacheKeyGeneratorTest { @Test fun defaultValues() = runTest { - val store = ApolloStore( + val cacheManager = CacheManager( normalizedCacheFactory = MemoryCacheFactory(), cacheKeyGenerator = IdCacheKeyGenerator(), cacheResolver = IdCacheKeyResolver(), ) - val apolloClient = ApolloClient.Builder().networkTransport(QueueTestNetworkTransport()).store(store).build() + val apolloClient = ApolloClient.Builder().networkTransport(QueueTestNetworkTransport()).cacheManager(cacheManager).build() val query = GetUser2Query("42") apolloClient.enqueueTestResponse(query, GetUser2Query.Data(GetUser2Query.User2(id = "42", name = "John", email = "a@a.com"))) apolloClient.query(query).fetchPolicy(FetchPolicy.NetworkOnly).execute() @@ -37,12 +37,12 @@ class IdCacheKeyGeneratorTest { @Test fun customIdField() = runTest { - val store = ApolloStore( + val cacheManager = CacheManager( normalizedCacheFactory = MemoryCacheFactory(), cacheKeyGenerator = IdCacheKeyGenerator("userId"), cacheResolver = IdCacheKeyResolver(idFields = listOf("userId")), ) - val apolloClient = ApolloClient.Builder().networkTransport(QueueTestNetworkTransport()).store(store).build() + val apolloClient = ApolloClient.Builder().networkTransport(QueueTestNetworkTransport()).cacheManager(cacheManager).build() val query = GetUserByIdQuery("42") apolloClient.enqueueTestResponse(query, GetUserByIdQuery.Data(GetUserByIdQuery.UserById(userId = "42", name = "John", email = "a@a.com"))) apolloClient.query(query).fetchPolicy(FetchPolicy.NetworkOnly).execute() @@ -53,12 +53,12 @@ class IdCacheKeyGeneratorTest { @Test fun lists() = runTest { - val store = ApolloStore( + val cacheManager = CacheManager( normalizedCacheFactory = MemoryCacheFactory(), cacheKeyGenerator = IdCacheKeyGenerator("id"), cacheResolver = IdCacheKeyResolver(idListFields = listOf("ids", "userIds")), ) - val apolloClient = ApolloClient.Builder().networkTransport(QueueTestNetworkTransport()).store(store).build() + val apolloClient = ApolloClient.Builder().networkTransport(QueueTestNetworkTransport()).cacheManager(cacheManager).build() val query1 = GetUsersQuery(listOf("42", "43")) apolloClient.enqueueTestResponse( query1, diff --git a/tests/normalized-cache/src/commonTest/kotlin/JsonScalarTest.kt b/tests/normalized-cache/src/commonTest/kotlin/JsonScalarTest.kt index f4c85cf3..e1a832c9 100644 --- a/tests/normalized-cache/src/commonTest/kotlin/JsonScalarTest.kt +++ b/tests/normalized-cache/src/commonTest/kotlin/JsonScalarTest.kt @@ -2,11 +2,11 @@ package test import com.apollographql.apollo.ApolloClient import com.apollographql.apollo.api.AnyAdapter -import com.apollographql.cache.normalized.ApolloStore +import com.apollographql.cache.normalized.CacheManager import com.apollographql.cache.normalized.FetchPolicy +import com.apollographql.cache.normalized.cacheManager import com.apollographql.cache.normalized.fetchPolicy import com.apollographql.cache.normalized.memory.MemoryCacheFactory -import com.apollographql.cache.normalized.store import com.apollographql.cache.normalized.testing.runTest import com.apollographql.mockserver.MockServer import com.apollographql.mockserver.enqueueString @@ -19,13 +19,13 @@ import kotlin.test.assertFalse class JsonScalarTest { private lateinit var mockServer: MockServer private lateinit var apolloClient: ApolloClient - private lateinit var store: ApolloStore + private lateinit var cacheManager: CacheManager private suspend fun setUp() { - store = ApolloStore(MemoryCacheFactory()) + cacheManager = CacheManager(MemoryCacheFactory()) mockServer = MockServer() apolloClient = ApolloClient.Builder().serverUrl(mockServer.url()) - .store(store) + .cacheManager(cacheManager) .addCustomScalarAdapter(Json.type, AnyAdapter) .build() } diff --git a/tests/normalized-cache/src/commonTest/kotlin/OptimisticCacheTest.kt b/tests/normalized-cache/src/commonTest/kotlin/OptimisticCacheTest.kt index d42656b3..41833cd7 100644 --- a/tests/normalized-cache/src/commonTest/kotlin/OptimisticCacheTest.kt +++ b/tests/normalized-cache/src/commonTest/kotlin/OptimisticCacheTest.kt @@ -2,15 +2,15 @@ package test import com.apollographql.apollo.ApolloClient import com.apollographql.apollo.api.Optional -import com.apollographql.cache.normalized.ApolloStore +import com.apollographql.cache.normalized.CacheManager import com.apollographql.cache.normalized.FetchPolicy import com.apollographql.cache.normalized.api.CacheKey import com.apollographql.cache.normalized.api.IdCacheKeyGenerator +import com.apollographql.cache.normalized.cacheManager import com.apollographql.cache.normalized.fetchPolicy import com.apollographql.cache.normalized.memory.MemoryCacheFactory import com.apollographql.cache.normalized.optimisticUpdates import com.apollographql.cache.normalized.refetchPolicy -import com.apollographql.cache.normalized.store import com.apollographql.cache.normalized.testing.runTest import com.apollographql.cache.normalized.watch import com.apollographql.mockserver.MockServer @@ -34,12 +34,12 @@ import kotlin.test.assertEquals class OptimisticCacheTest { private lateinit var mockServer: MockServer private lateinit var apolloClient: ApolloClient - private lateinit var store: ApolloStore + private lateinit var cacheManager: CacheManager private suspend fun setUp() { - store = ApolloStore(MemoryCacheFactory(), cacheKeyGenerator = IdCacheKeyGenerator()) + cacheManager = CacheManager(MemoryCacheFactory(), cacheKeyGenerator = IdCacheKeyGenerator()) mockServer = MockServer() - apolloClient = ApolloClient.Builder().serverUrl(mockServer.url()).store(store).build() + apolloClient = ApolloClient.Builder().serverUrl(mockServer.url()).cacheManager(cacheManager).build() } private suspend fun tearDown() { @@ -70,12 +70,12 @@ class OptimisticCacheTest { ) ) ) - store.writeOptimisticUpdates( + cacheManager.writeOptimisticUpdates( operation = query, data = data, mutationId = mutationId, ).also { - store.publish(it) + cacheManager.publish(it) } var response = apolloClient.query(query).fetchPolicy(FetchPolicy.CacheOnly).execute() @@ -85,7 +85,7 @@ class OptimisticCacheTest { assertEquals("SuperMan", response.data?.hero?.friends?.get(0)?.name) assertEquals("Batman", response.data?.hero?.friends?.get(1)?.name) - store.rollbackOptimisticUpdates(mutationId) + cacheManager.rollbackOptimisticUpdates(mutationId) response = apolloClient.query(query).fetchPolicy(FetchPolicy.CacheOnly).execute() assertEquals("R2-D2", response.data?.hero?.name) @@ -118,13 +118,13 @@ class OptimisticCacheTest { ) ) ) - store.writeOptimisticUpdates( + cacheManager.writeOptimisticUpdates( HeroAndFriendsNamesFragmentImpl(), mutationId = mutationId, cacheKey = CacheKey("""hero({"episode":"JEDI"})"""), data = data, ).also { - store.publish(it) + cacheManager.publish(it) } var response = apolloClient.query(query).fetchPolicy(FetchPolicy.CacheOnly).execute() @@ -134,7 +134,7 @@ class OptimisticCacheTest { assertEquals("SuperMan", response.data?.hero?.friends?.get(0)?.name) assertEquals("Batman", response.data?.hero?.friends?.get(1)?.name) - store.rollbackOptimisticUpdates(mutationId) + cacheManager.rollbackOptimisticUpdates(mutationId) response = apolloClient.query(query).fetchPolicy(FetchPolicy.CacheOnly).execute() assertEquals("R2-D2", response.data?.hero?.name) @@ -173,12 +173,12 @@ class OptimisticCacheTest { ) ) ) - store.writeOptimisticUpdates( + cacheManager.writeOptimisticUpdates( operation = query1, data = data1, mutationId = mutationId1, ).also { - store.publish(it) + cacheManager.publish(it) } // check if query1 see optimistic updates @@ -204,12 +204,12 @@ class OptimisticCacheTest { "Beast" ) ) - store.writeOptimisticUpdates( + cacheManager.writeOptimisticUpdates( operation = query2, data = data2, mutationId = mutationId2, ).also { - store.publish(it) + cacheManager.publish(it) } // check if query1 sees data2 @@ -228,7 +228,7 @@ class OptimisticCacheTest { assertEquals("Beast", response2.data?.hero?.name) // rollback data1 - store.rollbackOptimisticUpdates(mutationId1) + cacheManager.rollbackOptimisticUpdates(mutationId1) // check if query2 sees the rollback response1 = apolloClient.query(query1).fetchPolicy(FetchPolicy.CacheOnly).execute() @@ -248,7 +248,7 @@ class OptimisticCacheTest { assertEquals("Beast", response2.data?.hero?.name) // rollback query2 optimistic updates - store.rollbackOptimisticUpdates(mutationId2) + cacheManager.rollbackOptimisticUpdates(mutationId2) // check if query2 see the latest optimistic updates response2 = apolloClient.query(query2).fetchPolicy(FetchPolicy.CacheOnly).execute() @@ -375,24 +375,24 @@ class OptimisticCacheTest { ) ) ) - store.writeOptimisticUpdates( + cacheManager.writeOptimisticUpdates( operation = query1, data = data1, mutationId = mutationId1, ).also { - store.publish(it) + cacheManager.publish(it) } val data2 = HeroNameWithIdQuery.Data(HeroNameWithIdQuery.Hero( "1000", "Spiderman" ) ) - store.writeOptimisticUpdates( + cacheManager.writeOptimisticUpdates( operation = query2, data = data2, mutationId = mutationId2, ).also { - store.publish(it) + cacheManager.publish(it) } // check if query1 see optimistic updates @@ -412,7 +412,7 @@ class OptimisticCacheTest { assertEquals("Spiderman", response2.data?.hero?.name) // rollback query2 optimistic updates - store.rollbackOptimisticUpdates(mutationId2) + cacheManager.rollbackOptimisticUpdates(mutationId2) // check if query1 see the latest optimistic updates response1 = apolloClient.query(query1).fetchPolicy(FetchPolicy.CacheOnly).execute() @@ -431,7 +431,7 @@ class OptimisticCacheTest { assertEquals("Robocop", response2.data?.hero?.name) // rollback query1 optimistic updates - store.rollbackOptimisticUpdates(mutationId1) + cacheManager.rollbackOptimisticUpdates(mutationId1) // check if query1 see the latest non-optimistic updates response1 = apolloClient.query(query1).fetchPolicy(FetchPolicy.CacheOnly).execute() diff --git a/tests/normalized-cache/src/commonTest/kotlin/OtherCacheTest.kt b/tests/normalized-cache/src/commonTest/kotlin/OtherCacheTest.kt index 1b2b7d0b..475076f2 100644 --- a/tests/normalized-cache/src/commonTest/kotlin/OtherCacheTest.kt +++ b/tests/normalized-cache/src/commonTest/kotlin/OtherCacheTest.kt @@ -3,14 +3,14 @@ package test import com.apollographql.apollo.ApolloClient import com.apollographql.apollo.api.composeJsonResponse import com.apollographql.apollo.exception.CacheMissException -import com.apollographql.cache.normalized.ApolloStore +import com.apollographql.cache.normalized.CacheManager import com.apollographql.cache.normalized.FetchPolicy import com.apollographql.cache.normalized.api.CacheKey import com.apollographql.cache.normalized.api.IdCacheKeyGenerator import com.apollographql.cache.normalized.api.IdCacheKeyResolver +import com.apollographql.cache.normalized.cacheManager import com.apollographql.cache.normalized.fetchPolicy import com.apollographql.cache.normalized.memory.MemoryCacheFactory -import com.apollographql.cache.normalized.store import com.apollographql.cache.normalized.testing.keyToString import com.apollographql.cache.normalized.testing.runTest import com.apollographql.mockserver.MockServer @@ -34,12 +34,12 @@ import kotlin.test.assertTrue class OtherCacheTest { private lateinit var mockServer: MockServer private lateinit var apolloClient: ApolloClient - private lateinit var store: ApolloStore + private lateinit var cacheManager: CacheManager private suspend fun setUp() { - store = ApolloStore(MemoryCacheFactory(), cacheKeyGenerator = IdCacheKeyGenerator(), cacheResolver = IdCacheKeyResolver()) + cacheManager = CacheManager(MemoryCacheFactory(), cacheKeyGenerator = IdCacheKeyGenerator(), cacheResolver = IdCacheKeyResolver()) mockServer = MockServer() - apolloClient = ApolloClient.Builder().serverUrl(mockServer.url()).store(store).build() + apolloClient = ApolloClient.Builder().serverUrl(mockServer.url()).cacheManager(cacheManager).build() } private suspend fun tearDown() { @@ -186,7 +186,7 @@ class OtherCacheTest { mockServer.enqueueString(mutation.composeJsonResponse(data)) apolloClient.mutation(mutation).execute() - val storeData = store.readOperation(mutation).data + val storeData = cacheManager.readOperation(mutation).data assertEquals(data, storeData) } } diff --git a/tests/normalized-cache/src/commonTest/kotlin/StoreTest.kt b/tests/normalized-cache/src/commonTest/kotlin/StoreTest.kt index 1d2e8eb7..cbce9527 100644 --- a/tests/normalized-cache/src/commonTest/kotlin/StoreTest.kt +++ b/tests/normalized-cache/src/commonTest/kotlin/StoreTest.kt @@ -6,16 +6,16 @@ import com.apollographql.apollo.api.StringAdapter import com.apollographql.apollo.exception.CacheMissException import com.apollographql.apollo.testing.QueueTestNetworkTransport import com.apollographql.apollo.testing.enqueueTestResponse -import com.apollographql.cache.normalized.ApolloStore +import com.apollographql.cache.normalized.CacheManager import com.apollographql.cache.normalized.FetchPolicy import com.apollographql.cache.normalized.api.CacheKey import com.apollographql.cache.normalized.api.IdCacheKeyGenerator import com.apollographql.cache.normalized.api.IdCacheKeyResolver +import com.apollographql.cache.normalized.cacheManager import com.apollographql.cache.normalized.fetchPolicy import com.apollographql.cache.normalized.isFromCache import com.apollographql.cache.normalized.memory.MemoryCacheFactory import com.apollographql.cache.normalized.normalizedCache -import com.apollographql.cache.normalized.store import com.apollographql.cache.normalized.testing.runTest import normalizer.CharacterNameByIdQuery import normalizer.ColorQuery @@ -33,11 +33,11 @@ import kotlin.test.assertIs */ class StoreTest { private lateinit var apolloClient: ApolloClient - private lateinit var store: ApolloStore + private lateinit var cacheManager: CacheManager private fun setUp() { - store = ApolloStore(MemoryCacheFactory(), cacheKeyGenerator = IdCacheKeyGenerator(), cacheResolver = IdCacheKeyResolver()) - apolloClient = ApolloClient.Builder().networkTransport(QueueTestNetworkTransport()).store(store).build() + cacheManager = CacheManager(MemoryCacheFactory(), cacheKeyGenerator = IdCacheKeyGenerator(), cacheResolver = IdCacheKeyResolver()) + apolloClient = ApolloClient.Builder().networkTransport(QueueTestNetworkTransport()).cacheManager(cacheManager).build() } @Test @@ -46,7 +46,7 @@ class StoreTest { assertFriendIsCached("1002", "Han Solo") // remove the root query object - var removed = store.remove(CacheKey("Character:2001")) + var removed = cacheManager.remove(CacheKey("Character:2001")) assertEquals(true, removed) // Trying to get the full response should fail @@ -57,7 +57,7 @@ class StoreTest { assertFriendIsCached("1002", "Han Solo") // remove a single object from the list - removed = store.remove(CacheKey("Character:1002")) + removed = cacheManager.remove(CacheKey("Character:1002")) assertEquals(true, removed) // Trying to get the full response should fail @@ -79,7 +79,7 @@ class StoreTest { assertFriendIsCached("1003", "Leia Organa") // Now remove multiple keys - val removed = store.remove(listOf(CacheKey("Character:1002"), CacheKey("Character:1000"))) + val removed = cacheManager.remove(listOf(CacheKey("Character:1002"), CacheKey("Character:1000"))) assertEquals(2, removed) @@ -100,7 +100,7 @@ class StoreTest { assertFriendIsCached("1003", "Leia Organa") // test remove root query object - val removed = store.remove(CacheKey("Character:2001"), true) + val removed = cacheManager.remove(CacheKey("Character:2001"), true) assertEquals(true, removed) // Nothing should be cached anymore @@ -116,7 +116,7 @@ class StoreTest { // put everything in the cache storeAllFriends() - store.accessCache { + cacheManager.accessCache { it.remove(CacheKey("Character:1000"), false) } assertFriendIsNotCached("1000") @@ -127,8 +127,8 @@ class StoreTest { storeAllFriends() assertFriendIsCached("1000", "Luke Skywalker") - val newStore = ApolloStore(MemoryCacheFactory()) - val newClient = apolloClient.newBuilder().store(newStore).build() + val newCacheManager = CacheManager(MemoryCacheFactory()) + val newClient = apolloClient.newBuilder().cacheManager(newCacheManager).build() assertFriendIsNotCached("1000", newClient) } diff --git a/tests/normalized-cache/src/commonTest/kotlin/WatcherErrorHandlingTest.kt b/tests/normalized-cache/src/commonTest/kotlin/WatcherErrorHandlingTest.kt index 20165e5a..7658a6fa 100644 --- a/tests/normalized-cache/src/commonTest/kotlin/WatcherErrorHandlingTest.kt +++ b/tests/normalized-cache/src/commonTest/kotlin/WatcherErrorHandlingTest.kt @@ -5,13 +5,13 @@ import com.apollographql.apollo.ApolloClient import com.apollographql.apollo.api.ApolloResponse import com.apollographql.apollo.exception.ApolloHttpException import com.apollographql.apollo.exception.CacheMissException -import com.apollographql.cache.normalized.ApolloStore +import com.apollographql.cache.normalized.CacheManager import com.apollographql.cache.normalized.FetchPolicy import com.apollographql.cache.normalized.api.IdCacheKeyGenerator +import com.apollographql.cache.normalized.cacheManager import com.apollographql.cache.normalized.fetchPolicy import com.apollographql.cache.normalized.memory.MemoryCacheFactory import com.apollographql.cache.normalized.refetchPolicy -import com.apollographql.cache.normalized.store import com.apollographql.cache.normalized.testing.runTest import com.apollographql.cache.normalized.watch import com.apollographql.mockserver.MockServer @@ -31,12 +31,12 @@ import kotlin.test.assertNull class WatcherErrorHandlingTest { private lateinit var mockServer: MockServer private lateinit var apolloClient: ApolloClient - private lateinit var store: ApolloStore + private lateinit var cacheManager: CacheManager private suspend fun setUp() { - store = ApolloStore(MemoryCacheFactory(), cacheKeyGenerator = IdCacheKeyGenerator()) + cacheManager = CacheManager(MemoryCacheFactory(), cacheKeyGenerator = IdCacheKeyGenerator()) mockServer = MockServer() - apolloClient = ApolloClient.Builder().serverUrl(mockServer.url()).store(store).build() + apolloClient = ApolloClient.Builder().serverUrl(mockServer.url()).cacheManager(cacheManager).build() } private fun tearDown() { diff --git a/tests/normalized-cache/src/commonTest/kotlin/WatcherTest.kt b/tests/normalized-cache/src/commonTest/kotlin/WatcherTest.kt index aa93c918..bed32232 100644 --- a/tests/normalized-cache/src/commonTest/kotlin/WatcherTest.kt +++ b/tests/normalized-cache/src/commonTest/kotlin/WatcherTest.kt @@ -9,14 +9,14 @@ import com.apollographql.apollo.exception.CacheMissException import com.apollographql.apollo.testing.QueueTestNetworkTransport import com.apollographql.apollo.testing.enqueueTestNetworkError import com.apollographql.apollo.testing.enqueueTestResponse -import com.apollographql.cache.normalized.ApolloStore +import com.apollographql.cache.normalized.CacheManager import com.apollographql.cache.normalized.FetchPolicy import com.apollographql.cache.normalized.api.IdCacheKeyGenerator +import com.apollographql.cache.normalized.cacheManager import com.apollographql.cache.normalized.fetchPolicy import com.apollographql.cache.normalized.memory.MemoryCacheFactory import com.apollographql.cache.normalized.normalizedCache import com.apollographql.cache.normalized.refetchPolicy -import com.apollographql.cache.normalized.store import com.apollographql.cache.normalized.testing.runTest import com.apollographql.cache.normalized.watch import com.apollographql.mockserver.MockResponse @@ -47,11 +47,11 @@ import kotlin.time.Duration.Companion.minutes class WatcherTest { private lateinit var apolloClient: ApolloClient - private lateinit var store: ApolloStore + private lateinit var cacheManager: CacheManager private fun setUp() { - store = ApolloStore(MemoryCacheFactory(), cacheKeyGenerator = IdCacheKeyGenerator()) - apolloClient = ApolloClient.Builder().networkTransport(QueueTestNetworkTransport()).store(store).build() + cacheManager = CacheManager(MemoryCacheFactory(), cacheKeyGenerator = IdCacheKeyGenerator()) + apolloClient = ApolloClient.Builder().networkTransport(QueueTestNetworkTransport()).cacheManager(cacheManager).build() } private val episodeHeroNameData = EpisodeHeroNameQuery.Data(EpisodeHeroNameQuery.Hero("R2-D2")) @@ -177,8 +177,8 @@ class WatcherTest { ) ) - store.writeOperation(operation, data).also { - store.publish(it) + cacheManager.writeOperation(operation, data).also { + cacheManager.publish(it) } assertEquals(channel.awaitElement()?.hero?.name, "Artoo") @@ -657,8 +657,8 @@ class WatcherTest { assertEquals("R2-D2", awaitItem().data?.hero?.name) // Clear the cache - store.clearAll() - store.publish(ApolloStore.ALL_KEYS) + cacheManager.clearAll() + cacheManager.publish(CacheManager.ALL_KEYS) assertIs(awaitItem().exception) } } diff --git a/tests/normalized-cache/src/commonTest/kotlin/circular/CircularCacheReadTest.kt b/tests/normalized-cache/src/commonTest/kotlin/circular/CircularCacheReadTest.kt index 0b01fcb7..07bb8a00 100644 --- a/tests/normalized-cache/src/commonTest/kotlin/circular/CircularCacheReadTest.kt +++ b/tests/normalized-cache/src/commonTest/kotlin/circular/CircularCacheReadTest.kt @@ -1,7 +1,7 @@ package test.circular import circular.GetUserQuery -import com.apollographql.cache.normalized.ApolloStore +import com.apollographql.cache.normalized.CacheManager import com.apollographql.cache.normalized.memory.MemoryCacheFactory import com.apollographql.cache.normalized.testing.runTest import kotlin.test.Test @@ -10,7 +10,7 @@ import kotlin.test.assertEquals class CircularCacheReadTest { @Test fun circularReferenceDoesNotStackOverflow() = runTest { - val store = ApolloStore(MemoryCacheFactory()) + val store = CacheManager(MemoryCacheFactory()) val operation = GetUserQuery() diff --git a/tests/normalized-cache/src/commonTest/kotlin/declarativecache/DeclarativeCacheTest.kt b/tests/normalized-cache/src/commonTest/kotlin/declarativecache/DeclarativeCacheTest.kt index bc2b4308..932d09b1 100644 --- a/tests/normalized-cache/src/commonTest/kotlin/declarativecache/DeclarativeCacheTest.kt +++ b/tests/normalized-cache/src/commonTest/kotlin/declarativecache/DeclarativeCacheTest.kt @@ -1,6 +1,6 @@ package test.declarativecache -import com.apollographql.cache.normalized.ApolloStore +import com.apollographql.cache.normalized.CacheManager import com.apollographql.cache.normalized.api.CacheKey import com.apollographql.cache.normalized.api.CacheResolver import com.apollographql.cache.normalized.api.FieldPolicyCacheResolver @@ -22,7 +22,7 @@ class DeclarativeCacheTest { @Test fun typePolicyIsWorking() = runTest { - val store = ApolloStore(MemoryCacheFactory()) + val store = CacheManager(MemoryCacheFactory()) // Write a book at the "promo" path val promoOperation = GetPromoBookQuery() @@ -42,7 +42,7 @@ class DeclarativeCacheTest { @Test fun fallbackIdIsWorking() = runTest { - val store = ApolloStore(MemoryCacheFactory()) + val store = CacheManager(MemoryCacheFactory()) // Write a library at the "promo" path val promoOperation = GetPromoLibraryQuery() @@ -62,7 +62,7 @@ class DeclarativeCacheTest { @Test fun fieldPolicyIsWorking() = runTest { - val store = ApolloStore(MemoryCacheFactory()) + val store = CacheManager(MemoryCacheFactory()) val bookQuery1 = GetPromoBookQuery() val bookData1 = GetPromoBookQuery.Data(GetPromoBookQuery.PromoBook("Promo", "42", "Book")) @@ -107,7 +107,7 @@ class DeclarativeCacheTest { return FieldPolicyCacheResolver.resolveField(context) } } - val store = ApolloStore(MemoryCacheFactory(), cacheResolver = cacheResolver) + val store = CacheManager(MemoryCacheFactory(), cacheResolver = cacheResolver) val promoOperation = GetPromoBookQuery() store.writeOperation(promoOperation, GetPromoBookQuery.Data(GetPromoBookQuery.PromoBook("Title1", "1", "Book"))) diff --git a/tests/normalized-cache/src/concurrentTest/kotlin/MemoryCacheOnlyTest.kt b/tests/normalized-cache/src/concurrentTest/kotlin/MemoryCacheOnlyTest.kt index a7b10204..a45e5325 100644 --- a/tests/normalized-cache/src/concurrentTest/kotlin/MemoryCacheOnlyTest.kt +++ b/tests/normalized-cache/src/concurrentTest/kotlin/MemoryCacheOnlyTest.kt @@ -2,17 +2,17 @@ import com.apollographql.apollo.ApolloClient import com.apollographql.apollo.exception.CacheMissException import com.apollographql.apollo.testing.QueueTestNetworkTransport import com.apollographql.apollo.testing.enqueueTestResponse -import com.apollographql.cache.normalized.ApolloStore +import com.apollographql.cache.normalized.CacheManager import com.apollographql.cache.normalized.FetchPolicy import com.apollographql.cache.normalized.api.CacheKey import com.apollographql.cache.normalized.api.Record +import com.apollographql.cache.normalized.cacheManager import com.apollographql.cache.normalized.fetchPolicy import com.apollographql.cache.normalized.memory.MemoryCache import com.apollographql.cache.normalized.memory.MemoryCacheFactory import com.apollographql.cache.normalized.memoryCacheOnly import com.apollographql.cache.normalized.sql.SqlNormalizedCache import com.apollographql.cache.normalized.sql.SqlNormalizedCacheFactory -import com.apollographql.cache.normalized.store import com.apollographql.cache.normalized.testing.runTest import main.GetUserQuery import kotlin.reflect.KClass @@ -23,8 +23,8 @@ import kotlin.test.assertIs class MemoryCacheOnlyTest { @Test fun memoryCacheOnlyDoesNotStoreInSqlCache() = runTest { - val store = ApolloStore(MemoryCacheFactory().chain(SqlNormalizedCacheFactory())).also { it.clearAll() } - val apolloClient = ApolloClient.Builder().networkTransport(QueueTestNetworkTransport()).store(store).build() + val store = CacheManager(MemoryCacheFactory().chain(SqlNormalizedCacheFactory())).also { it.clearAll() } + val apolloClient = ApolloClient.Builder().networkTransport(QueueTestNetworkTransport()).cacheManager(store).build() val query = GetUserQuery() apolloClient.enqueueTestResponse(query, GetUserQuery.Data(GetUserQuery.User("John", "a@a.com"))) apolloClient.query(query).memoryCacheOnly(true).execute() @@ -35,12 +35,12 @@ class MemoryCacheOnlyTest { @Test fun memoryCacheOnlyDoesNotReadFromSqlCache() = runTest { - val store = ApolloStore(MemoryCacheFactory().chain(SqlNormalizedCacheFactory())).also { it.clearAll() } + val store = CacheManager(MemoryCacheFactory().chain(SqlNormalizedCacheFactory())).also { it.clearAll() } val query = GetUserQuery() store.writeOperation(query, GetUserQuery.Data(GetUserQuery.User("John", "a@a.com"))) - val store2 = ApolloStore(MemoryCacheFactory().chain(SqlNormalizedCacheFactory())) - val apolloClient = ApolloClient.Builder().serverUrl("unused").store(store2).build() + val store2 = CacheManager(MemoryCacheFactory().chain(SqlNormalizedCacheFactory())) + val apolloClient = ApolloClient.Builder().serverUrl("unused").cacheManager(store2).build() // The record in is in the SQL cache, but we request not to access it assertIs( apolloClient.query(query).fetchPolicy(FetchPolicy.CacheOnly).memoryCacheOnly(true).execute().exception diff --git a/tests/normalized-cache/src/jvmTest/kotlin/CacheConcurrencyTest.kt b/tests/normalized-cache/src/jvmTest/kotlin/CacheConcurrencyTest.kt index b4df802e..f7aafbba 100644 --- a/tests/normalized-cache/src/jvmTest/kotlin/CacheConcurrencyTest.kt +++ b/tests/normalized-cache/src/jvmTest/kotlin/CacheConcurrencyTest.kt @@ -3,9 +3,9 @@ package test import com.apollographql.apollo.ApolloClient import com.apollographql.apollo.testing.QueueTestNetworkTransport import com.apollographql.apollo.testing.enqueueTestResponse -import com.apollographql.cache.normalized.ApolloStore +import com.apollographql.cache.normalized.CacheManager +import com.apollographql.cache.normalized.cacheManager import com.apollographql.cache.normalized.memory.MemoryCacheFactory -import com.apollographql.cache.normalized.store import com.apollographql.cache.normalized.testing.runTest import kotlinx.coroutines.asCoroutineDispatcher import kotlinx.coroutines.joinAll @@ -18,13 +18,13 @@ class CacheConcurrencyTest { @Test fun storeConcurrently() = runTest { - val store = ApolloStore(MemoryCacheFactory(maxSizeBytes = 1000)) + val cacheManager = CacheManager(MemoryCacheFactory(maxSizeBytes = 1000)) val executor = Executors.newFixedThreadPool(10) val dispatcher = executor.asCoroutineDispatcher() val apolloClient = ApolloClient.Builder() .networkTransport(QueueTestNetworkTransport()) - .store(store) + .cacheManager(cacheManager) .dispatcher(dispatcher) .build() @@ -39,6 +39,6 @@ class CacheConcurrencyTest { }.joinAll() executor.shutdown() - println(store.dump().values.toList()[1].map { (k, v) -> "$k -> ${v.fields}" }.joinToString("\n")) + println(cacheManager.dump().values.toList()[1].map { (k, v) -> "$k -> ${v.fields}" }.joinToString("\n")) } } diff --git a/tests/normalized-cache/src/jvmTest/kotlin/WriteToCacheAsynchronouslyTest.kt b/tests/normalized-cache/src/jvmTest/kotlin/WriteToCacheAsynchronouslyTest.kt index 8f6eccb4..250a8330 100644 --- a/tests/normalized-cache/src/jvmTest/kotlin/WriteToCacheAsynchronouslyTest.kt +++ b/tests/normalized-cache/src/jvmTest/kotlin/WriteToCacheAsynchronouslyTest.kt @@ -1,11 +1,11 @@ package test import com.apollographql.apollo.ApolloClient -import com.apollographql.cache.normalized.ApolloStore +import com.apollographql.cache.normalized.CacheManager import com.apollographql.cache.normalized.api.CacheHeaders import com.apollographql.cache.normalized.api.CacheKey +import com.apollographql.cache.normalized.cacheManager import com.apollographql.cache.normalized.memory.MemoryCacheFactory -import com.apollographql.cache.normalized.store import com.apollographql.cache.normalized.testing.runTest import com.apollographql.cache.normalized.writeToCacheAsynchronously import com.apollographql.mockserver.MockServer @@ -26,16 +26,16 @@ import kotlin.test.assertNull class WriteToCacheAsynchronouslyTest { private lateinit var mockServer: MockServer private lateinit var apolloClient: ApolloClient - private lateinit var store: ApolloStore + private lateinit var cacheManager: CacheManager private var dispatcher = Executors.newSingleThreadExecutor().asCoroutineDispatcher() private suspend fun setUp() { - store = ApolloStore(MemoryCacheFactory()) + cacheManager = CacheManager(MemoryCacheFactory()) mockServer = MockServer() apolloClient = ApolloClient.Builder() .serverUrl(mockServer.url()) .dispatcher(dispatcher) - .store(store) + .cacheManager(cacheManager) .build() } @@ -58,7 +58,7 @@ class WriteToCacheAsynchronouslyTest { .execute() - val record = store.accessCache { it.loadRecord(QUERY_ROOT_KEY, CacheHeaders.NONE) } + val record = cacheManager.accessCache { it.loadRecord(QUERY_ROOT_KEY, CacheHeaders.NONE) } assertNull(record) } } @@ -76,7 +76,7 @@ class WriteToCacheAsynchronouslyTest { .writeToCacheAsynchronously(false) .execute() - val record = store.accessCache { it.loadRecord(QUERY_ROOT_KEY, CacheHeaders.NONE) } + val record = cacheManager.accessCache { it.loadRecord(QUERY_ROOT_KEY, CacheHeaders.NONE) } assertNotNull(record) } } diff --git a/tests/pagination/src/commonTest/kotlin/ConnectionPaginationTest.kt b/tests/pagination/src/commonTest/kotlin/ConnectionPaginationTest.kt index e42d466f..d87fc127 100644 --- a/tests/pagination/src/commonTest/kotlin/ConnectionPaginationTest.kt +++ b/tests/pagination/src/commonTest/kotlin/ConnectionPaginationTest.kt @@ -2,7 +2,7 @@ package pagination import com.apollographql.apollo.api.Error import com.apollographql.apollo.api.Optional -import com.apollographql.cache.normalized.ApolloStore +import com.apollographql.cache.normalized.CacheManager import com.apollographql.cache.normalized.api.ConnectionMetadataGenerator import com.apollographql.cache.normalized.api.ConnectionRecordMerger import com.apollographql.cache.normalized.api.FieldPolicyCacheResolver @@ -37,14 +37,14 @@ class ConnectionPaginationTest { } private fun test(cacheFactory: NormalizedCacheFactory) = runTest { - val apolloStore = ApolloStore( + val cacheManager = CacheManager( normalizedCacheFactory = cacheFactory, cacheKeyGenerator = TypePolicyCacheKeyGenerator, metadataGenerator = ConnectionMetadataGenerator(Pagination.connectionTypes), cacheResolver = FieldPolicyCacheResolver, recordMerger = ConnectionRecordMerger ) - apolloStore.clearAll() + cacheManager.clearAll() // First page val query1 = UsersQuery(first = Optional.Present(2)) @@ -70,10 +70,10 @@ class ConnectionPaginationTest { ) } } - apolloStore.writeOperation(query1, data1) - var dataFromStore = apolloStore.readOperation(query1).data + cacheManager.writeOperation(query1, data1) + var dataFromStore = cacheManager.readOperation(query1).data assertEquals(data1, dataFromStore) - assertChainedCachesAreEqual(apolloStore) + assertChainedCachesAreEqual(cacheManager) // Page after val query2 = UsersQuery(first = Optional.Present(2), after = Optional.Present("xx43")) @@ -99,8 +99,8 @@ class ConnectionPaginationTest { ) } } - apolloStore.writeOperation(query2, data2) - dataFromStore = apolloStore.readOperation(query1).data + cacheManager.writeOperation(query2, data2) + dataFromStore = cacheManager.readOperation(query1).data var expectedData = UsersQuery.Data { users = buildUserConnection { pageInfo = buildPageInfo { @@ -136,7 +136,7 @@ class ConnectionPaginationTest { } } assertEquals(expectedData, dataFromStore) - assertChainedCachesAreEqual(apolloStore) + assertChainedCachesAreEqual(cacheManager) // Page after val query3 = UsersQuery(first = Optional.Present(2), after = Optional.Present("xx45")) @@ -162,8 +162,8 @@ class ConnectionPaginationTest { ) } } - apolloStore.writeOperation(query3, data3) - dataFromStore = apolloStore.readOperation(query1).data + cacheManager.writeOperation(query3, data3) + dataFromStore = cacheManager.readOperation(query1).data expectedData = UsersQuery.Data { users = buildUserConnection { pageInfo = buildPageInfo { @@ -211,7 +211,7 @@ class ConnectionPaginationTest { } } assertEquals(expectedData, dataFromStore) - assertChainedCachesAreEqual(apolloStore) + assertChainedCachesAreEqual(cacheManager) // Page before val query4 = UsersQuery(last = Optional.Present(2), before = Optional.Present("xx42")) @@ -237,8 +237,8 @@ class ConnectionPaginationTest { ) } } - apolloStore.writeOperation(query4, data4) - dataFromStore = apolloStore.readOperation(query1).data + cacheManager.writeOperation(query4, data4) + dataFromStore = cacheManager.readOperation(query1).data expectedData = UsersQuery.Data { users = buildUserConnection { pageInfo = buildPageInfo { @@ -298,7 +298,7 @@ class ConnectionPaginationTest { } } assertEquals(expectedData, dataFromStore) - assertChainedCachesAreEqual(apolloStore) + assertChainedCachesAreEqual(cacheManager) // Non-contiguous page (should reset) val query5 = UsersQuery(first = Optional.Present(2), after = Optional.Present("xx50")) @@ -324,10 +324,10 @@ class ConnectionPaginationTest { ) } } - apolloStore.writeOperation(query5, data5) - dataFromStore = apolloStore.readOperation(query1).data + cacheManager.writeOperation(query5, data5) + dataFromStore = cacheManager.readOperation(query1).data assertEquals(data5, dataFromStore) - assertChainedCachesAreEqual(apolloStore) + assertChainedCachesAreEqual(cacheManager) // Empty page (should keep previous result) val query6 = UsersQuery(first = Optional.Present(2), after = Optional.Present("xx51")) @@ -340,10 +340,10 @@ class ConnectionPaginationTest { edges = emptyList() } } - apolloStore.writeOperation(query6, data6) - dataFromStore = apolloStore.readOperation(query1).data + cacheManager.writeOperation(query6, data6) + dataFromStore = cacheManager.readOperation(query1).data assertEquals(data5, dataFromStore) - assertChainedCachesAreEqual(apolloStore) + assertChainedCachesAreEqual(cacheManager) } @Test @@ -362,21 +362,21 @@ class ConnectionPaginationTest { } private fun errorTest(cacheFactory: NormalizedCacheFactory) = runTest { - val apolloStore = ApolloStore( + val cacheManager = CacheManager( normalizedCacheFactory = cacheFactory, cacheKeyGenerator = TypePolicyCacheKeyGenerator, metadataGenerator = ConnectionMetadataGenerator(Pagination.connectionTypes), cacheResolver = FieldPolicyCacheResolver, recordMerger = ConnectionRecordMerger ) - apolloStore.clearAll() + cacheManager.clearAll() val query = UsersQuery(first = Optional.Present(2)) - apolloStore.writeOperation( + cacheManager.writeOperation( operation = query, data = UsersQuery.Data { users = null }, errors = listOf(Error.Builder("An error occurred.").path(listOf("users")).build()) ) - val responseFromStore = apolloStore.readOperation(query) + val responseFromStore = cacheManager.readOperation(query) assertEquals(UsersQuery.Data { users = null }, responseFromStore.data) assertEquals(1, responseFromStore.errors?.size) assertEquals("An error occurred.", responseFromStore.errors?.firstOrNull()?.message) diff --git a/tests/pagination/src/commonTest/kotlin/ConnectionProgrammaticPaginationTest.kt b/tests/pagination/src/commonTest/kotlin/ConnectionProgrammaticPaginationTest.kt index 65511788..45ce8825 100644 --- a/tests/pagination/src/commonTest/kotlin/ConnectionProgrammaticPaginationTest.kt +++ b/tests/pagination/src/commonTest/kotlin/ConnectionProgrammaticPaginationTest.kt @@ -1,7 +1,7 @@ package pagination import com.apollographql.apollo.api.Optional -import com.apollographql.cache.normalized.ApolloStore +import com.apollographql.cache.normalized.CacheManager import com.apollographql.cache.normalized.api.ConnectionEmbeddedFieldsProvider import com.apollographql.cache.normalized.api.ConnectionFieldKeyGenerator import com.apollographql.cache.normalized.api.ConnectionMetadataGenerator @@ -41,7 +41,7 @@ class ConnectionProgrammaticPaginationTest { private fun test(cacheFactory: NormalizedCacheFactory) = runTest { val connectionTypes = setOf(UserConnection.type.name) val connectionFields = mapOf(Query.type.name to listOf("users")) - val apolloStore = ApolloStore( + val cacheManager = CacheManager( normalizedCacheFactory = cacheFactory, cacheKeyGenerator = TypePolicyCacheKeyGenerator, metadataGenerator = ConnectionMetadataGenerator(connectionTypes), @@ -53,7 +53,7 @@ class ConnectionProgrammaticPaginationTest { connectionFields = connectionFields ), ) - apolloStore.clearAll() + cacheManager.clearAll() // First page val query1 = UsersQuery(first = Optional.Present(2)) @@ -79,10 +79,10 @@ class ConnectionProgrammaticPaginationTest { ) } } - apolloStore.writeOperation(query1, data1) - var dataFromStore = apolloStore.readOperation(query1).data + cacheManager.writeOperation(query1, data1) + var dataFromStore = cacheManager.readOperation(query1).data assertEquals(data1, dataFromStore) - assertChainedCachesAreEqual(apolloStore) + assertChainedCachesAreEqual(cacheManager) // Page after val query2 = UsersQuery(first = Optional.Present(2), after = Optional.Present("xx43")) @@ -108,8 +108,8 @@ class ConnectionProgrammaticPaginationTest { ) } } - apolloStore.writeOperation(query2, data2) - dataFromStore = apolloStore.readOperation(query1).data + cacheManager.writeOperation(query2, data2) + dataFromStore = cacheManager.readOperation(query1).data var expectedData = UsersQuery.Data { users = buildUserConnection { pageInfo = buildPageInfo { @@ -145,7 +145,7 @@ class ConnectionProgrammaticPaginationTest { } } assertEquals(expectedData, dataFromStore) - assertChainedCachesAreEqual(apolloStore) + assertChainedCachesAreEqual(cacheManager) // Page after val query3 = UsersQuery(first = Optional.Present(2), after = Optional.Present("xx45")) @@ -171,8 +171,8 @@ class ConnectionProgrammaticPaginationTest { ) } } - apolloStore.writeOperation(query3, data3) - dataFromStore = apolloStore.readOperation(query1).data + cacheManager.writeOperation(query3, data3) + dataFromStore = cacheManager.readOperation(query1).data expectedData = UsersQuery.Data { users = buildUserConnection { pageInfo = buildPageInfo { @@ -220,7 +220,7 @@ class ConnectionProgrammaticPaginationTest { } } assertEquals(expectedData, dataFromStore) - assertChainedCachesAreEqual(apolloStore) + assertChainedCachesAreEqual(cacheManager) // Page before val query4 = UsersQuery(last = Optional.Present(2), before = Optional.Present("xx42")) @@ -246,8 +246,8 @@ class ConnectionProgrammaticPaginationTest { ) } } - apolloStore.writeOperation(query4, data4) - dataFromStore = apolloStore.readOperation(query1).data + cacheManager.writeOperation(query4, data4) + dataFromStore = cacheManager.readOperation(query1).data expectedData = UsersQuery.Data { users = buildUserConnection { pageInfo = buildPageInfo { @@ -307,7 +307,7 @@ class ConnectionProgrammaticPaginationTest { } } assertEquals(expectedData, dataFromStore) - assertChainedCachesAreEqual(apolloStore) + assertChainedCachesAreEqual(cacheManager) // Non-contiguous page (should reset) val query5 = UsersQuery(first = Optional.Present(2), after = Optional.Present("xx50")) @@ -333,10 +333,10 @@ class ConnectionProgrammaticPaginationTest { ) } } - apolloStore.writeOperation(query5, data5) - dataFromStore = apolloStore.readOperation(query1).data + cacheManager.writeOperation(query5, data5) + dataFromStore = cacheManager.readOperation(query1).data assertEquals(data5, dataFromStore) - assertChainedCachesAreEqual(apolloStore) + assertChainedCachesAreEqual(cacheManager) // Empty page (should keep previous result) val query6 = UsersQuery(first = Optional.Present(2), after = Optional.Present("xx51")) @@ -349,10 +349,10 @@ class ConnectionProgrammaticPaginationTest { edges = emptyList() } } - apolloStore.writeOperation(query6, data6) - dataFromStore = apolloStore.readOperation(query1).data + cacheManager.writeOperation(query6, data6) + dataFromStore = cacheManager.readOperation(query1).data assertEquals(data5, dataFromStore) - assertChainedCachesAreEqual(apolloStore) + assertChainedCachesAreEqual(cacheManager) } } diff --git a/tests/pagination/src/commonTest/kotlin/ConnectionWithNodesPaginationTest.kt b/tests/pagination/src/commonTest/kotlin/ConnectionWithNodesPaginationTest.kt index 43cc0e2c..9c2d7bdb 100644 --- a/tests/pagination/src/commonTest/kotlin/ConnectionWithNodesPaginationTest.kt +++ b/tests/pagination/src/commonTest/kotlin/ConnectionWithNodesPaginationTest.kt @@ -1,7 +1,7 @@ package pagination import com.apollographql.apollo.api.Optional -import com.apollographql.cache.normalized.ApolloStore +import com.apollographql.cache.normalized.CacheManager import com.apollographql.cache.normalized.api.ConnectionMetadataGenerator import com.apollographql.cache.normalized.api.ConnectionRecordMerger import com.apollographql.cache.normalized.api.FieldPolicyCacheResolver @@ -35,14 +35,14 @@ class ConnectionWithNodesPaginationTest { } private fun test(cacheFactory: NormalizedCacheFactory) = runTest { - val apolloStore = ApolloStore( + val cacheManager = CacheManager( normalizedCacheFactory = cacheFactory, cacheKeyGenerator = TypePolicyCacheKeyGenerator, metadataGenerator = ConnectionMetadataGenerator(Pagination.connectionTypes), cacheResolver = FieldPolicyCacheResolver, recordMerger = ConnectionRecordMerger ) - apolloStore.clearAll() + cacheManager.clearAll() // First page val query1 = UsersQuery(first = Optional.Present(2)) @@ -62,10 +62,10 @@ class ConnectionWithNodesPaginationTest { ) } } - apolloStore.writeOperation(query1, data1) - var dataFromStore = apolloStore.readOperation(query1).data + cacheManager.writeOperation(query1, data1) + var dataFromStore = cacheManager.readOperation(query1).data assertEquals(data1, dataFromStore) - assertChainedCachesAreEqual(apolloStore) + assertChainedCachesAreEqual(cacheManager) // Page after val query2 = UsersQuery(first = Optional.Present(2), after = Optional.Present("xx43")) @@ -85,8 +85,8 @@ class ConnectionWithNodesPaginationTest { ) } } - apolloStore.writeOperation(query2, data2) - dataFromStore = apolloStore.readOperation(query1).data + cacheManager.writeOperation(query2, data2) + dataFromStore = cacheManager.readOperation(query1).data var expectedData = UsersQuery.Data { users = buildUserConnection { pageInfo = buildPageInfo { @@ -110,7 +110,7 @@ class ConnectionWithNodesPaginationTest { } } assertEquals(expectedData, dataFromStore) - assertChainedCachesAreEqual(apolloStore) + assertChainedCachesAreEqual(cacheManager) // Page after val query3 = UsersQuery(first = Optional.Present(2), after = Optional.Present("xx45")) @@ -130,8 +130,8 @@ class ConnectionWithNodesPaginationTest { ) } } - apolloStore.writeOperation(query3, data3) - dataFromStore = apolloStore.readOperation(query1).data + cacheManager.writeOperation(query3, data3) + dataFromStore = cacheManager.readOperation(query1).data expectedData = UsersQuery.Data { users = buildUserConnection { pageInfo = buildPageInfo { @@ -161,7 +161,7 @@ class ConnectionWithNodesPaginationTest { } } assertEquals(expectedData, dataFromStore) - assertChainedCachesAreEqual(apolloStore) + assertChainedCachesAreEqual(cacheManager) // Page before val query4 = UsersQuery(last = Optional.Present(2), before = Optional.Present("xx42")) @@ -181,8 +181,8 @@ class ConnectionWithNodesPaginationTest { ) } } - apolloStore.writeOperation(query4, data4) - dataFromStore = apolloStore.readOperation(query1).data + cacheManager.writeOperation(query4, data4) + dataFromStore = cacheManager.readOperation(query1).data expectedData = UsersQuery.Data { users = buildUserConnection { pageInfo = buildPageInfo { @@ -218,7 +218,7 @@ class ConnectionWithNodesPaginationTest { } } assertEquals(expectedData, dataFromStore) - assertChainedCachesAreEqual(apolloStore) + assertChainedCachesAreEqual(cacheManager) // Non-contiguous page (should reset) val query5 = UsersQuery(first = Optional.Present(2), after = Optional.Present("xx50")) @@ -238,10 +238,10 @@ class ConnectionWithNodesPaginationTest { ) } } - apolloStore.writeOperation(query5, data5) - dataFromStore = apolloStore.readOperation(query1).data + cacheManager.writeOperation(query5, data5) + dataFromStore = cacheManager.readOperation(query1).data assertEquals(data5, dataFromStore) - assertChainedCachesAreEqual(apolloStore) + assertChainedCachesAreEqual(cacheManager) // Empty page (should keep previous result) val query6 = UsersQuery(first = Optional.Present(2), after = Optional.Present("xx51")) @@ -255,10 +255,10 @@ class ConnectionWithNodesPaginationTest { } } - apolloStore.writeOperation(query6, data6) - dataFromStore = apolloStore.readOperation(query1).data + cacheManager.writeOperation(query6, data6) + dataFromStore = cacheManager.readOperation(query1).data assertEquals(data5, dataFromStore) - assertChainedCachesAreEqual(apolloStore) + assertChainedCachesAreEqual(cacheManager) } } diff --git a/tests/pagination/src/commonTest/kotlin/CursorBasedPaginationTest.kt b/tests/pagination/src/commonTest/kotlin/CursorBasedPaginationTest.kt index 95ce8023..b7cc4046 100644 --- a/tests/pagination/src/commonTest/kotlin/CursorBasedPaginationTest.kt +++ b/tests/pagination/src/commonTest/kotlin/CursorBasedPaginationTest.kt @@ -4,7 +4,7 @@ import com.apollographql.apollo.ApolloClient import com.apollographql.apollo.api.Optional import com.apollographql.apollo.testing.QueueTestNetworkTransport import com.apollographql.apollo.testing.enqueueTestResponse -import com.apollographql.cache.normalized.ApolloStore +import com.apollographql.cache.normalized.CacheManager import com.apollographql.cache.normalized.FetchPolicy import com.apollographql.cache.normalized.api.ConnectionMetadataGenerator import com.apollographql.cache.normalized.api.ConnectionRecordMerger @@ -43,14 +43,14 @@ class CursorBasedPaginationTest { } private fun test(cacheFactory: NormalizedCacheFactory) = runTest { - val apolloStore = ApolloStore( + val cacheManager = CacheManager( normalizedCacheFactory = cacheFactory, cacheKeyGenerator = TypePolicyCacheKeyGenerator, metadataGenerator = ConnectionMetadataGenerator(setOf("UserConnection")), cacheResolver = FieldPolicyCacheResolver, recordMerger = ConnectionRecordMerger ) - apolloStore.clearAll() + cacheManager.clearAll() // First page val query1 = UsersQuery(first = Optional.Present(2)) @@ -76,10 +76,10 @@ class CursorBasedPaginationTest { ) } } - apolloStore.writeOperation(query1, data1) - var dataFromStore = apolloStore.readOperation(query1).data + cacheManager.writeOperation(query1, data1) + var dataFromStore = cacheManager.readOperation(query1).data assertEquals(data1, dataFromStore) - assertChainedCachesAreEqual(apolloStore) + assertChainedCachesAreEqual(cacheManager) // Page after val query2 = UsersQuery(first = Optional.Present(2), after = Optional.Present("xx43")) @@ -105,8 +105,8 @@ class CursorBasedPaginationTest { ) } } - apolloStore.writeOperation(query2, data2) - dataFromStore = apolloStore.readOperation(query1).data + cacheManager.writeOperation(query2, data2) + dataFromStore = cacheManager.readOperation(query1).data var expectedData = UsersQuery.Data { users = buildUserConnection { pageInfo = buildPageInfo { @@ -142,7 +142,7 @@ class CursorBasedPaginationTest { } } assertEquals(expectedData, dataFromStore) - assertChainedCachesAreEqual(apolloStore) + assertChainedCachesAreEqual(cacheManager) // Page after val query3 = UsersQuery(first = Optional.Present(2), after = Optional.Present("xx45")) @@ -168,8 +168,8 @@ class CursorBasedPaginationTest { ) } } - apolloStore.writeOperation(query3, data3) - dataFromStore = apolloStore.readOperation(query1).data + cacheManager.writeOperation(query3, data3) + dataFromStore = cacheManager.readOperation(query1).data expectedData = UsersQuery.Data { users = buildUserConnection { pageInfo = buildPageInfo { @@ -217,7 +217,7 @@ class CursorBasedPaginationTest { } } assertEquals(expectedData, dataFromStore) - assertChainedCachesAreEqual(apolloStore) + assertChainedCachesAreEqual(cacheManager) // Page before val query4 = UsersQuery(last = Optional.Present(2), before = Optional.Present("xx42")) @@ -243,8 +243,8 @@ class CursorBasedPaginationTest { ) } } - apolloStore.writeOperation(query4, data4) - dataFromStore = apolloStore.readOperation(query1).data + cacheManager.writeOperation(query4, data4) + dataFromStore = cacheManager.readOperation(query1).data expectedData = UsersQuery.Data { users = buildUserConnection { pageInfo = buildPageInfo { @@ -304,7 +304,7 @@ class CursorBasedPaginationTest { } } assertEquals(expectedData, dataFromStore) - assertChainedCachesAreEqual(apolloStore) + assertChainedCachesAreEqual(cacheManager) // Non-contiguous page (should reset) val query5 = UsersQuery(first = Optional.Present(2), after = Optional.Present("xx50")) @@ -330,10 +330,10 @@ class CursorBasedPaginationTest { ) } } - apolloStore.writeOperation(query5, data5) - dataFromStore = apolloStore.readOperation(query1).data + cacheManager.writeOperation(query5, data5) + dataFromStore = cacheManager.readOperation(query1).data assertEquals(data5, dataFromStore) - assertChainedCachesAreEqual(apolloStore) + assertChainedCachesAreEqual(cacheManager) // Empty page (should keep previous result) val query6 = UsersQuery(first = Optional.Present(2), after = Optional.Present("xx51")) @@ -346,10 +346,10 @@ class CursorBasedPaginationTest { edges = emptyList() } } - apolloStore.writeOperation(query6, data6) - dataFromStore = apolloStore.readOperation(query1).data + cacheManager.writeOperation(query6, data6) + dataFromStore = cacheManager.readOperation(query1).data assertEquals(data5, dataFromStore) - assertChainedCachesAreEqual(apolloStore) + assertChainedCachesAreEqual(cacheManager) } @Test diff --git a/tests/pagination/src/commonTest/kotlin/OffsetBasedWithArrayPaginationTest.kt b/tests/pagination/src/commonTest/kotlin/OffsetBasedWithArrayPaginationTest.kt index b5789422..60ed12d5 100644 --- a/tests/pagination/src/commonTest/kotlin/OffsetBasedWithArrayPaginationTest.kt +++ b/tests/pagination/src/commonTest/kotlin/OffsetBasedWithArrayPaginationTest.kt @@ -2,7 +2,7 @@ package pagination import com.apollographql.apollo.api.Optional import com.apollographql.apollo.api.json.ApolloJsonElement -import com.apollographql.cache.normalized.ApolloStore +import com.apollographql.cache.normalized.CacheManager import com.apollographql.cache.normalized.api.FieldPolicyCacheResolver import com.apollographql.cache.normalized.api.FieldRecordMerger import com.apollographql.cache.normalized.api.MetadataGenerator @@ -36,14 +36,14 @@ class OffsetBasedWithArrayPaginationTest { } private fun test(cacheFactory: NormalizedCacheFactory) = runTest { - val apolloStore = ApolloStore( + val cacheManager = CacheManager( normalizedCacheFactory = cacheFactory, cacheKeyGenerator = TypePolicyCacheKeyGenerator, metadataGenerator = OffsetPaginationMetadataGenerator("users"), cacheResolver = FieldPolicyCacheResolver, recordMerger = FieldRecordMerger(OffsetPaginationFieldMerger()) ) - apolloStore.clearAll() + cacheManager.clearAll() // First page val query1 = UsersQuery(offset = Optional.Present(42), limit = Optional.Present(2)) @@ -53,10 +53,10 @@ class OffsetBasedWithArrayPaginationTest { buildUser { id = "43" }, ) } - apolloStore.writeOperation(query1, data1) - var dataFromStore = apolloStore.readOperation(query1).data + cacheManager.writeOperation(query1, data1) + var dataFromStore = cacheManager.readOperation(query1).data assertEquals(data1, dataFromStore) - assertChainedCachesAreEqual(apolloStore) + assertChainedCachesAreEqual(cacheManager) // Page after val query2 = UsersQuery(offset = Optional.Present(44), limit = Optional.Present(2)) @@ -66,8 +66,8 @@ class OffsetBasedWithArrayPaginationTest { buildUser { id = "45" }, ) } - apolloStore.writeOperation(query2, data2) - dataFromStore = apolloStore.readOperation(query1).data + cacheManager.writeOperation(query2, data2) + dataFromStore = cacheManager.readOperation(query1).data var expectedData = UsersQuery.Data { users = listOf( buildUser { id = "42" }, @@ -77,7 +77,7 @@ class OffsetBasedWithArrayPaginationTest { ) } assertEquals(expectedData, dataFromStore) - assertChainedCachesAreEqual(apolloStore) + assertChainedCachesAreEqual(cacheManager) // Page in the middle val query3 = UsersQuery(offset = Optional.Present(44), limit = Optional.Present(3)) @@ -88,8 +88,8 @@ class OffsetBasedWithArrayPaginationTest { buildUser { id = "46" }, ) } - apolloStore.writeOperation(query3, data3) - dataFromStore = apolloStore.readOperation(query1).data + cacheManager.writeOperation(query3, data3) + dataFromStore = cacheManager.readOperation(query1).data expectedData = UsersQuery.Data { users = listOf( buildUser { id = "42" }, @@ -100,7 +100,7 @@ class OffsetBasedWithArrayPaginationTest { ) } assertEquals(expectedData, dataFromStore) - assertChainedCachesAreEqual(apolloStore) + assertChainedCachesAreEqual(cacheManager) // Page before val query4 = UsersQuery(offset = Optional.Present(40), limit = Optional.Present(2)) @@ -110,8 +110,8 @@ class OffsetBasedWithArrayPaginationTest { buildUser { id = "41" }, ) } - apolloStore.writeOperation(query4, data4) - dataFromStore = apolloStore.readOperation(query1).data + cacheManager.writeOperation(query4, data4) + dataFromStore = cacheManager.readOperation(query1).data expectedData = UsersQuery.Data { users = listOf( buildUser { id = "40" }, @@ -124,7 +124,7 @@ class OffsetBasedWithArrayPaginationTest { ) } assertEquals(expectedData, dataFromStore) - assertChainedCachesAreEqual(apolloStore) + assertChainedCachesAreEqual(cacheManager) // Non-contiguous page (should reset) val query5 = UsersQuery(offset = Optional.Present(50), limit = Optional.Present(2)) @@ -134,20 +134,20 @@ class OffsetBasedWithArrayPaginationTest { buildUser { id = "51" }, ) } - apolloStore.writeOperation(query5, data5) - dataFromStore = apolloStore.readOperation(query1).data + cacheManager.writeOperation(query5, data5) + dataFromStore = cacheManager.readOperation(query1).data assertEquals(data5, dataFromStore) - assertChainedCachesAreEqual(apolloStore) + assertChainedCachesAreEqual(cacheManager) // Empty page (should keep previous result) val query6 = UsersQuery(offset = Optional.Present(52), limit = Optional.Present(2)) val data6 = UsersQuery.Data { users = emptyList() } - apolloStore.writeOperation(query6, data6) - dataFromStore = apolloStore.readOperation(query1).data + cacheManager.writeOperation(query6, data6) + dataFromStore = cacheManager.readOperation(query1).data assertEquals(data5, dataFromStore) - assertChainedCachesAreEqual(apolloStore) + assertChainedCachesAreEqual(cacheManager) } private class OffsetPaginationMetadataGenerator(private val fieldName: String) : MetadataGenerator { diff --git a/tests/pagination/src/commonTest/kotlin/OffsetBasedWithPageAndInputPaginationTest.kt b/tests/pagination/src/commonTest/kotlin/OffsetBasedWithPageAndInputPaginationTest.kt index 1ad53c95..4484c507 100644 --- a/tests/pagination/src/commonTest/kotlin/OffsetBasedWithPageAndInputPaginationTest.kt +++ b/tests/pagination/src/commonTest/kotlin/OffsetBasedWithPageAndInputPaginationTest.kt @@ -5,7 +5,7 @@ import com.apollographql.apollo.api.CompiledField import com.apollographql.apollo.api.Executable import com.apollographql.apollo.api.Optional import com.apollographql.apollo.api.json.ApolloJsonElement -import com.apollographql.cache.normalized.ApolloStore +import com.apollographql.cache.normalized.CacheManager import com.apollographql.cache.normalized.api.DefaultFieldKeyGenerator import com.apollographql.cache.normalized.api.FieldKeyContext import com.apollographql.cache.normalized.api.FieldKeyGenerator @@ -43,7 +43,7 @@ class OffsetBasedWithPageAndInputPaginationTest { } private fun test(cacheFactory: NormalizedCacheFactory) = runTest { - val apolloStore = ApolloStore( + val cacheManager = CacheManager( normalizedCacheFactory = cacheFactory, cacheKeyGenerator = TypePolicyCacheKeyGenerator, metadataGenerator = OffsetPaginationMetadataGenerator("UserPage"), @@ -51,7 +51,7 @@ class OffsetBasedWithPageAndInputPaginationTest { recordMerger = FieldRecordMerger(OffsetPaginationFieldMerger()), fieldKeyGenerator = UsersFieldKeyGenerator, ) - apolloStore.clearAll() + cacheManager.clearAll() // First page val query1 = UsersQuery(offset = Optional.Present(42), limit = Optional.Present(2)) @@ -63,10 +63,10 @@ class OffsetBasedWithPageAndInputPaginationTest { ) } } - apolloStore.writeOperation(query1, data1) - var dataFromStore = apolloStore.readOperation(query1).data + cacheManager.writeOperation(query1, data1) + var dataFromStore = cacheManager.readOperation(query1).data assertEquals(data1, dataFromStore) - assertChainedCachesAreEqual(apolloStore) + assertChainedCachesAreEqual(cacheManager) // Page after val query2 = UsersQuery(offset = Optional.Present(44), limit = Optional.Present(2)) @@ -78,8 +78,8 @@ class OffsetBasedWithPageAndInputPaginationTest { ) } } - apolloStore.writeOperation(query2, data2) - dataFromStore = apolloStore.readOperation(query1).data + cacheManager.writeOperation(query2, data2) + dataFromStore = cacheManager.readOperation(query1).data var expectedData = UsersQuery.Data { users = buildUserPage { users = listOf( @@ -91,7 +91,7 @@ class OffsetBasedWithPageAndInputPaginationTest { } } assertEquals(expectedData, dataFromStore) - assertChainedCachesAreEqual(apolloStore) + assertChainedCachesAreEqual(cacheManager) // Page in the middle val query3 = UsersQuery(offset = Optional.Present(44), limit = Optional.Present(3)) @@ -104,8 +104,8 @@ class OffsetBasedWithPageAndInputPaginationTest { ) } } - apolloStore.writeOperation(query3, data3) - dataFromStore = apolloStore.readOperation(query1).data + cacheManager.writeOperation(query3, data3) + dataFromStore = cacheManager.readOperation(query1).data expectedData = UsersQuery.Data { users = buildUserPage { users = listOf( @@ -118,7 +118,7 @@ class OffsetBasedWithPageAndInputPaginationTest { } } assertEquals(expectedData, dataFromStore) - assertChainedCachesAreEqual(apolloStore) + assertChainedCachesAreEqual(cacheManager) // Page before val query4 = UsersQuery(offset = Optional.Present(40), limit = Optional.Present(2)) @@ -130,8 +130,8 @@ class OffsetBasedWithPageAndInputPaginationTest { ) } } - apolloStore.writeOperation(query4, data4) - dataFromStore = apolloStore.readOperation(query1).data + cacheManager.writeOperation(query4, data4) + dataFromStore = cacheManager.readOperation(query1).data expectedData = UsersQuery.Data { users = buildUserPage { users = listOf( @@ -146,7 +146,7 @@ class OffsetBasedWithPageAndInputPaginationTest { } } assertEquals(expectedData, dataFromStore) - assertChainedCachesAreEqual(apolloStore) + assertChainedCachesAreEqual(cacheManager) // Non-contiguous page (should reset) val query5 = UsersQuery(offset = Optional.Present(50), limit = Optional.Present(2)) @@ -158,10 +158,10 @@ class OffsetBasedWithPageAndInputPaginationTest { ) } } - apolloStore.writeOperation(query5, data5) - dataFromStore = apolloStore.readOperation(query1).data + cacheManager.writeOperation(query5, data5) + dataFromStore = cacheManager.readOperation(query1).data assertEquals(data5, dataFromStore) - assertChainedCachesAreEqual(apolloStore) + assertChainedCachesAreEqual(cacheManager) // Empty page (should keep previous result) val query6 = UsersQuery(offset = Optional.Present(52), limit = Optional.Present(2)) @@ -170,10 +170,10 @@ class OffsetBasedWithPageAndInputPaginationTest { users = emptyList() } } - apolloStore.writeOperation(query6, data6) - dataFromStore = apolloStore.readOperation(query1).data + cacheManager.writeOperation(query6, data6) + dataFromStore = cacheManager.readOperation(query1).data assertEquals(data5, dataFromStore) - assertChainedCachesAreEqual(apolloStore) + assertChainedCachesAreEqual(cacheManager) } private class OffsetPaginationMetadataGenerator(private val typeName: String) : MetadataGenerator { diff --git a/tests/pagination/src/commonTest/kotlin/OffsetBasedWithPagePaginationTest.kt b/tests/pagination/src/commonTest/kotlin/OffsetBasedWithPagePaginationTest.kt index ed2bdfdc..8d13af80 100644 --- a/tests/pagination/src/commonTest/kotlin/OffsetBasedWithPagePaginationTest.kt +++ b/tests/pagination/src/commonTest/kotlin/OffsetBasedWithPagePaginationTest.kt @@ -2,7 +2,7 @@ package pagination import com.apollographql.apollo.api.Optional import com.apollographql.apollo.api.json.ApolloJsonElement -import com.apollographql.cache.normalized.ApolloStore +import com.apollographql.cache.normalized.CacheManager import com.apollographql.cache.normalized.api.CacheKey import com.apollographql.cache.normalized.api.FieldPolicyCacheResolver import com.apollographql.cache.normalized.api.FieldRecordMerger @@ -39,14 +39,14 @@ class OffsetBasedWithPagePaginationTest { } private fun test(cacheFactory: NormalizedCacheFactory) = runTest { - val apolloStore = ApolloStore( + val cacheManager = CacheManager( normalizedCacheFactory = cacheFactory, cacheKeyGenerator = TypePolicyCacheKeyGenerator, metadataGenerator = OffsetPaginationMetadataGenerator("UserPage"), cacheResolver = FieldPolicyCacheResolver, recordMerger = FieldRecordMerger(OffsetPaginationFieldMerger()) ) - apolloStore.clearAll() + cacheManager.clearAll() // First page val query1 = UsersQuery(offset = Optional.Present(42), limit = Optional.Present(2)) @@ -58,10 +58,10 @@ class OffsetBasedWithPagePaginationTest { ) } } - apolloStore.writeOperation(query1, data1) - var dataFromStore = apolloStore.readOperation(query1).data + cacheManager.writeOperation(query1, data1) + var dataFromStore = cacheManager.readOperation(query1).data assertEquals(data1, dataFromStore) - assertChainedCachesAreEqual(apolloStore) + assertChainedCachesAreEqual(cacheManager) // Page after val query2 = UsersQuery(offset = Optional.Present(44), limit = Optional.Present(2)) @@ -73,8 +73,8 @@ class OffsetBasedWithPagePaginationTest { ) } } - apolloStore.writeOperation(query2, data2) - dataFromStore = apolloStore.readOperation(query1).data + cacheManager.writeOperation(query2, data2) + dataFromStore = cacheManager.readOperation(query1).data var expectedData = UsersQuery.Data { users = buildUserPage { users = listOf( @@ -86,7 +86,7 @@ class OffsetBasedWithPagePaginationTest { } } assertEquals(expectedData, dataFromStore) - assertChainedCachesAreEqual(apolloStore) + assertChainedCachesAreEqual(cacheManager) // Page in the middle val query3 = UsersQuery(offset = Optional.Present(44), limit = Optional.Present(3)) @@ -99,8 +99,8 @@ class OffsetBasedWithPagePaginationTest { ) } } - apolloStore.writeOperation(query3, data3) - dataFromStore = apolloStore.readOperation(query1).data + cacheManager.writeOperation(query3, data3) + dataFromStore = cacheManager.readOperation(query1).data expectedData = UsersQuery.Data { users = buildUserPage { users = listOf( @@ -113,7 +113,7 @@ class OffsetBasedWithPagePaginationTest { } } assertEquals(expectedData, dataFromStore) - assertChainedCachesAreEqual(apolloStore) + assertChainedCachesAreEqual(cacheManager) // Page before val query4 = UsersQuery(offset = Optional.Present(40), limit = Optional.Present(2)) @@ -125,8 +125,8 @@ class OffsetBasedWithPagePaginationTest { ) } } - apolloStore.writeOperation(query4, data4) - dataFromStore = apolloStore.readOperation(query1).data + cacheManager.writeOperation(query4, data4) + dataFromStore = cacheManager.readOperation(query1).data expectedData = UsersQuery.Data { users = buildUserPage { users = listOf( @@ -141,7 +141,7 @@ class OffsetBasedWithPagePaginationTest { } } assertEquals(expectedData, dataFromStore) - assertChainedCachesAreEqual(apolloStore) + assertChainedCachesAreEqual(cacheManager) // Non-contiguous page (should reset) val query5 = UsersQuery(offset = Optional.Present(50), limit = Optional.Present(2)) @@ -153,10 +153,10 @@ class OffsetBasedWithPagePaginationTest { ) } } - apolloStore.writeOperation(query5, data5) - dataFromStore = apolloStore.readOperation(query1).data + cacheManager.writeOperation(query5, data5) + dataFromStore = cacheManager.readOperation(query1).data assertEquals(data5, dataFromStore) - assertChainedCachesAreEqual(apolloStore) + assertChainedCachesAreEqual(cacheManager) // Empty page (should keep previous result) val query6 = UsersQuery(offset = Optional.Present(52), limit = Optional.Present(2)) @@ -165,10 +165,10 @@ class OffsetBasedWithPagePaginationTest { users = emptyList() } } - apolloStore.writeOperation(query6, data6) - dataFromStore = apolloStore.readOperation(query1).data + cacheManager.writeOperation(query6, data6) + dataFromStore = cacheManager.readOperation(query1).data assertEquals(data5, dataFromStore) - assertChainedCachesAreEqual(apolloStore) + assertChainedCachesAreEqual(cacheManager) } private class OffsetPaginationMetadataGenerator(private val typeName: String) : MetadataGenerator { @@ -227,8 +227,8 @@ class OffsetBasedWithPagePaginationTest { } } -internal fun assertChainedCachesAreEqual(apolloStore: ApolloStore) { - val dump = apolloStore.dump().filterKeys { +internal fun assertChainedCachesAreEqual(cacheManager: CacheManager) { + val dump = cacheManager.dump().filterKeys { // Ignore optimistic cache for comparison it.simpleName != "OptimisticNormalizedCache" } diff --git a/tests/partial-results/src/commonTest/kotlin/test/CachePartialResultTest.kt b/tests/partial-results/src/commonTest/kotlin/test/CachePartialResultTest.kt index 2b7f3f3f..5cb31ca5 100644 --- a/tests/partial-results/src/commonTest/kotlin/test/CachePartialResultTest.kt +++ b/tests/partial-results/src/commonTest/kotlin/test/CachePartialResultTest.kt @@ -8,7 +8,7 @@ import com.apollographql.apollo.api.Operation import com.apollographql.apollo.api.graphQLErrorOrNull import com.apollographql.apollo.interceptor.ApolloInterceptor import com.apollographql.apollo.interceptor.ApolloInterceptorChain -import com.apollographql.cache.normalized.ApolloStore +import com.apollographql.cache.normalized.CacheManager import com.apollographql.cache.normalized.FetchPolicy import com.apollographql.cache.normalized.api.CacheControlCacheResolver import com.apollographql.cache.normalized.api.CacheHeaders @@ -18,6 +18,7 @@ import com.apollographql.cache.normalized.api.IdCacheKeyGenerator import com.apollographql.cache.normalized.api.IdCacheKeyResolver import com.apollographql.cache.normalized.api.Record import com.apollographql.cache.normalized.api.SchemaCoordinatesMaxAgeProvider +import com.apollographql.cache.normalized.cacheManager import com.apollographql.cache.normalized.fetchFromCache import com.apollographql.cache.normalized.fetchPolicy import com.apollographql.cache.normalized.fetchPolicyInterceptor @@ -170,8 +171,8 @@ class CachePartialResultTest { ) ApolloClient.Builder() .serverUrl(mockServer.url()) - .store( - ApolloStore( + .cacheManager( + CacheManager( normalizedCacheFactory = MemoryCacheFactory(), cacheKeyGenerator = IdCacheKeyGenerator(), cacheResolver = IdCacheKeyResolver() @@ -441,8 +442,8 @@ class CachePartialResultTest { ) ApolloClient.Builder() .serverUrl(mockServer.url()) - .store( - ApolloStore( + .cacheManager( + CacheManager( normalizedCacheFactory = MemoryCacheFactory(), cacheKeyGenerator = IdCacheKeyGenerator(), cacheResolver = IdCacheKeyResolver() @@ -503,8 +504,8 @@ class CachePartialResultTest { ) ApolloClient.Builder() .serverUrl(mockServer.url()) - .store( - ApolloStore( + .cacheManager( + CacheManager( normalizedCacheFactory = MemoryCacheFactory(), cacheKeyGenerator = IdCacheKeyGenerator(), cacheResolver = IdCacheKeyResolver() diff --git a/tests/store-errors/src/commonTest/kotlin/test/StoreErrorsTest.kt b/tests/store-errors/src/commonTest/kotlin/test/StoreErrorsTest.kt index 9fda53c7..e15addc4 100644 --- a/tests/store-errors/src/commonTest/kotlin/test/StoreErrorsTest.kt +++ b/tests/store-errors/src/commonTest/kotlin/test/StoreErrorsTest.kt @@ -7,18 +7,18 @@ import com.apollographql.apollo.api.Error import com.apollographql.apollo.api.Operation import com.apollographql.apollo.interceptor.ApolloInterceptor import com.apollographql.apollo.interceptor.ApolloInterceptorChain -import com.apollographql.cache.normalized.ApolloStore +import com.apollographql.cache.normalized.CacheManager import com.apollographql.cache.normalized.FetchPolicy import com.apollographql.cache.normalized.api.CacheKey import com.apollographql.cache.normalized.api.Record import com.apollographql.cache.normalized.api.withErrors +import com.apollographql.cache.normalized.cacheManager import com.apollographql.cache.normalized.errorsReplaceCachedValues import com.apollographql.cache.normalized.fetchFromCache import com.apollographql.cache.normalized.fetchPolicy import com.apollographql.cache.normalized.fetchPolicyInterceptor import com.apollographql.cache.normalized.memory.MemoryCacheFactory import com.apollographql.cache.normalized.sql.SqlNormalizedCacheFactory -import com.apollographql.cache.normalized.store import com.apollographql.cache.normalized.testing.assertErrorsEquals import com.apollographql.cache.normalized.testing.runTest import com.apollographql.mockserver.MockServer @@ -41,11 +41,11 @@ class StoreErrorsTest { mockServer.close() } - private val memoryStore = ApolloStore(MemoryCacheFactory()) + private val memoryStore = CacheManager(MemoryCacheFactory()) - private val sqlStore = ApolloStore(SqlNormalizedCacheFactory()).also { it.clearAll() } + private val sqlStore = CacheManager(SqlNormalizedCacheFactory()).also { it.clearAll() } - private val memoryThenSqlStore = ApolloStore(MemoryCacheFactory().chain(SqlNormalizedCacheFactory())).also { it.clearAll() } + private val memoryThenSqlStore = CacheManager(MemoryCacheFactory().chain(SqlNormalizedCacheFactory())).also { it.clearAll() } @Test fun simpleMemory() = runTest(before = { setUp() }, after = { tearDown() }) { @@ -62,7 +62,7 @@ class StoreErrorsTest { simple(memoryThenSqlStore) } - private suspend fun simple(store: ApolloStore) { + private suspend fun simple(cacheManager: CacheManager) { mockServer.enqueueString( // language=JSON """ @@ -87,7 +87,7 @@ class StoreErrorsTest { ) ApolloClient.Builder() .serverUrl(mockServer.url()) - .store(store) + .cacheManager(cacheManager) .build() .use { apolloClient -> val networkResult = apolloClient.query(MeWithNickNameQuery()) @@ -141,7 +141,7 @@ class StoreErrorsTest { lists(memoryThenSqlStore) } - private suspend fun lists(store: ApolloStore) { + private suspend fun lists(cacheManager: CacheManager) { mockServer.enqueueString( // language=JSON """ @@ -176,7 +176,7 @@ class StoreErrorsTest { ) ApolloClient.Builder() .serverUrl(mockServer.url()) - .store(store) + .cacheManager(cacheManager) .build() .use { apolloClient -> val networkResult = apolloClient.query(UsersQuery(listOf("1", "2", "3"))) @@ -240,7 +240,7 @@ class StoreErrorsTest { composite(memoryThenSqlStore) } - private suspend fun composite(store: ApolloStore) { + private suspend fun composite(cacheManager: CacheManager) { mockServer.enqueueString( // language=JSON """ @@ -284,7 +284,7 @@ class StoreErrorsTest { ) ApolloClient.Builder() .serverUrl(mockServer.url()) - .store(store) + .cacheManager(cacheManager) .build() .use { apolloClient -> val networkResult = apolloClient.query(MeWithBestFriendQuery()) @@ -355,7 +355,7 @@ class StoreErrorsTest { aliases(memoryThenSqlStore) } - private suspend fun aliases(store: ApolloStore) { + private suspend fun aliases(cacheManager: CacheManager) { mockServer.enqueueString( // language=JSON """ @@ -380,7 +380,7 @@ class StoreErrorsTest { ) ApolloClient.Builder() .serverUrl(mockServer.url()) - .store(store) + .cacheManager(cacheManager) .build() .use { apolloClient -> val networkResult = apolloClient.query(DefaultProjectQuery()) @@ -433,7 +433,7 @@ class StoreErrorsTest { fragmentsAndAliases(memoryThenSqlStore) } - private fun fragmentsAndAliases(store: ApolloStore) = runTest(before = { setUp() }, after = { tearDown() }) { + private fun fragmentsAndAliases(cacheManager: CacheManager) = runTest(before = { setUp() }, after = { tearDown() }) { mockServer.enqueueString( // language=JSON """ @@ -472,7 +472,7 @@ class StoreErrorsTest { ) ApolloClient.Builder() .serverUrl(mockServer.url()) - .store(store) + .cacheManager(cacheManager) .build() .use { apolloClient -> val networkResult = apolloClient.query(WithFragmentsQuery()) @@ -547,7 +547,7 @@ class StoreErrorsTest { errorsReplaceCachedValues(memoryThenSqlStore) } - private suspend fun errorsReplaceCachedValues(store: ApolloStore) { + private suspend fun errorsReplaceCachedValues(cacheManager: CacheManager) { mockServer.enqueueString( // language=JSON """ @@ -612,7 +612,7 @@ class StoreErrorsTest { ApolloClient.Builder() .serverUrl(mockServer.url()) - .store(store) + .cacheManager(cacheManager) .build() .use { apolloClient -> val noErrorNetworkResult = apolloClient.query(MeWithNickNameQuery()) @@ -732,8 +732,8 @@ class StoreErrorsTest { writeOperation(memoryThenSqlStore) } - private fun writeOperation(store: ApolloStore) { - store.writeOperation( + private fun writeOperation(cacheManager: CacheManager) { + cacheManager.writeOperation( operation = MeWithNickNameQuery(), data = MeWithNickNameQuery.Data( MeWithNickNameQuery.Me( @@ -748,7 +748,7 @@ class StoreErrorsTest { Error.Builder("'nickName' can't be reached").path(listOf("me", "nickName")).build() ), ) - val responseFromCache = store.readOperation(MeWithNickNameQuery()) + val responseFromCache = cacheManager.readOperation(MeWithNickNameQuery()) assertEquals( MeWithNickNameQuery.Data( MeWithNickNameQuery.Me( From 259c915b659387e8964212f59dc2dfc674605395 Mon Sep 17 00:00:00 2001 From: BoD Date: Fri, 25 Apr 2025 14:58:52 +0200 Subject: [PATCH 05/11] Rename SimpleApolloStore -> ApolloStore --- normalized-cache/api/normalized-cache.api | 82 +++++++++---------- .../api/normalized-cache.klib.api | 70 ++++++++-------- .../{SimpleApolloStore.kt => ApolloStore.kt} | 2 +- .../cache/normalized/ClientCacheExtensions.kt | 6 +- .../cache/normalized/GarbageCollection.kt | 8 +- 5 files changed, 84 insertions(+), 84 deletions(-) rename normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/{SimpleApolloStore.kt => ApolloStore.kt} (99%) diff --git a/normalized-cache/api/normalized-cache.api b/normalized-cache/api/normalized-cache.api index a21037c6..112d3ac5 100644 --- a/normalized-cache/api/normalized-cache.api +++ b/normalized-cache/api/normalized-cache.api @@ -1,3 +1,36 @@ +public final class com/apollographql/cache/normalized/ApolloStore { + public fun (Lcom/apollographql/cache/normalized/CacheManager;Lcom/apollographql/apollo/api/CustomScalarAdapters;)V + public final fun accessCache (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public final fun clearAll ()Z + public final fun dispose ()V + public final fun dump ()Ljava/util/Map; + public final fun getCacheManager ()Lcom/apollographql/cache/normalized/CacheManager; + public final fun getChangedKeys ()Lkotlinx/coroutines/flow/SharedFlow; + public final fun getCustomScalarAdapters ()Lcom/apollographql/apollo/api/CustomScalarAdapters; + public final fun normalize-Hljz6HE (Lcom/apollographql/apollo/api/Executable;Ljava/util/Map;Ljava/lang/String;)Ljava/util/Map; + public static synthetic fun normalize-Hljz6HE$default (Lcom/apollographql/cache/normalized/ApolloStore;Lcom/apollographql/apollo/api/Executable;Ljava/util/Map;Ljava/lang/String;ILjava/lang/Object;)Ljava/util/Map; + public final fun publish (Ljava/util/Set;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public final fun readFragment-0aEo43o (Lcom/apollographql/apollo/api/Fragment;Ljava/lang/String;Lcom/apollographql/cache/normalized/api/CacheHeaders;)Lcom/apollographql/cache/normalized/CacheManager$ReadResult; + public static synthetic fun readFragment-0aEo43o$default (Lcom/apollographql/cache/normalized/ApolloStore;Lcom/apollographql/apollo/api/Fragment;Ljava/lang/String;Lcom/apollographql/cache/normalized/api/CacheHeaders;ILjava/lang/Object;)Lcom/apollographql/cache/normalized/CacheManager$ReadResult; + public final fun readOperation (Lcom/apollographql/apollo/api/Operation;Lcom/apollographql/cache/normalized/api/CacheHeaders;)Lcom/apollographql/apollo/api/ApolloResponse; + public static synthetic fun readOperation$default (Lcom/apollographql/cache/normalized/ApolloStore;Lcom/apollographql/apollo/api/Operation;Lcom/apollographql/cache/normalized/api/CacheHeaders;ILjava/lang/Object;)Lcom/apollographql/apollo/api/ApolloResponse; + public final fun remove (Ljava/util/List;Z)I + public static synthetic fun remove$default (Lcom/apollographql/cache/normalized/ApolloStore;Ljava/util/List;ZILjava/lang/Object;)I + public final fun remove-eNSUWrY (Ljava/lang/String;Z)Z + public static synthetic fun remove-eNSUWrY$default (Lcom/apollographql/cache/normalized/ApolloStore;Ljava/lang/String;ZILjava/lang/Object;)Z + public final fun rollbackOptimisticUpdates (Ljava/util/UUID;)Ljava/util/Set; + public final fun trim (JF)J + public static synthetic fun trim$default (Lcom/apollographql/cache/normalized/ApolloStore;JFILjava/lang/Object;)J + public final fun writeFragment-dEpVOtE (Lcom/apollographql/apollo/api/Fragment;Ljava/lang/String;Lcom/apollographql/apollo/api/Fragment$Data;Lcom/apollographql/cache/normalized/api/CacheHeaders;)Ljava/util/Set; + public static synthetic fun writeFragment-dEpVOtE$default (Lcom/apollographql/cache/normalized/ApolloStore;Lcom/apollographql/apollo/api/Fragment;Ljava/lang/String;Lcom/apollographql/apollo/api/Fragment$Data;Lcom/apollographql/cache/normalized/api/CacheHeaders;ILjava/lang/Object;)Ljava/util/Set; + public final fun writeOperation (Lcom/apollographql/apollo/api/Operation;Lcom/apollographql/apollo/api/Operation$Data;Ljava/util/List;Lcom/apollographql/cache/normalized/api/CacheHeaders;)Ljava/util/Set; + public final fun writeOperation (Lcom/apollographql/apollo/api/Operation;Ljava/util/Map;Lcom/apollographql/cache/normalized/api/CacheHeaders;)Ljava/util/Set; + public static synthetic fun writeOperation$default (Lcom/apollographql/cache/normalized/ApolloStore;Lcom/apollographql/apollo/api/Operation;Lcom/apollographql/apollo/api/Operation$Data;Ljava/util/List;Lcom/apollographql/cache/normalized/api/CacheHeaders;ILjava/lang/Object;)Ljava/util/Set; + public static synthetic fun writeOperation$default (Lcom/apollographql/cache/normalized/ApolloStore;Lcom/apollographql/apollo/api/Operation;Ljava/util/Map;Lcom/apollographql/cache/normalized/api/CacheHeaders;ILjava/lang/Object;)Ljava/util/Set; + public final fun writeOptimisticUpdates (Lcom/apollographql/apollo/api/Operation;Lcom/apollographql/apollo/api/Operation$Data;Ljava/util/UUID;)Ljava/util/Set; + public final fun writeOptimisticUpdates-dEpVOtE (Lcom/apollographql/apollo/api/Fragment;Ljava/lang/String;Lcom/apollographql/apollo/api/Fragment$Data;Ljava/util/UUID;)Ljava/util/Set; +} + public final class com/apollographql/cache/normalized/CacheInfo : com/apollographql/apollo/api/ExecutionContext$Element { public static final field Key Lcom/apollographql/cache/normalized/CacheInfo$Key; public synthetic fun (JJJJZZLcom/apollographql/apollo/exception/CacheMissException;Lcom/apollographql/apollo/exception/ApolloException;ZLkotlin/jvm/internal/DefaultConstructorMarker;)V @@ -120,18 +153,18 @@ public final class com/apollographql/cache/normalized/GarbageCollectResult { public final class com/apollographql/cache/normalized/GarbageCollectionKt { public static final fun allRecords (Lcom/apollographql/cache/normalized/api/NormalizedCache;)Ljava/util/Map; - public static final fun garbageCollect-SxA4cEA (Lcom/apollographql/cache/normalized/SimpleApolloStore;Lcom/apollographql/cache/normalized/api/MaxAgeProvider;J)Lcom/apollographql/cache/normalized/GarbageCollectResult; + public static final fun garbageCollect-SxA4cEA (Lcom/apollographql/cache/normalized/ApolloStore;Lcom/apollographql/cache/normalized/api/MaxAgeProvider;J)Lcom/apollographql/cache/normalized/GarbageCollectResult; public static final fun garbageCollect-SxA4cEA (Lcom/apollographql/cache/normalized/api/NormalizedCache;Lcom/apollographql/cache/normalized/api/MaxAgeProvider;J)Lcom/apollographql/cache/normalized/GarbageCollectResult; - public static synthetic fun garbageCollect-SxA4cEA$default (Lcom/apollographql/cache/normalized/SimpleApolloStore;Lcom/apollographql/cache/normalized/api/MaxAgeProvider;JILjava/lang/Object;)Lcom/apollographql/cache/normalized/GarbageCollectResult; + public static synthetic fun garbageCollect-SxA4cEA$default (Lcom/apollographql/cache/normalized/ApolloStore;Lcom/apollographql/cache/normalized/api/MaxAgeProvider;JILjava/lang/Object;)Lcom/apollographql/cache/normalized/GarbageCollectResult; public static synthetic fun garbageCollect-SxA4cEA$default (Lcom/apollographql/cache/normalized/api/NormalizedCache;Lcom/apollographql/cache/normalized/api/MaxAgeProvider;JILjava/lang/Object;)Lcom/apollographql/cache/normalized/GarbageCollectResult; public static final fun getReachableCacheKeys (Ljava/util/Map;)Ljava/util/Set; - public static final fun removeDanglingReferences (Lcom/apollographql/cache/normalized/SimpleApolloStore;)Lcom/apollographql/cache/normalized/RemovedFieldsAndRecords; + public static final fun removeDanglingReferences (Lcom/apollographql/cache/normalized/ApolloStore;)Lcom/apollographql/cache/normalized/RemovedFieldsAndRecords; public static final fun removeDanglingReferences (Lcom/apollographql/cache/normalized/api/NormalizedCache;)Lcom/apollographql/cache/normalized/RemovedFieldsAndRecords; - public static final fun removeStaleFields-SxA4cEA (Lcom/apollographql/cache/normalized/SimpleApolloStore;Lcom/apollographql/cache/normalized/api/MaxAgeProvider;J)Lcom/apollographql/cache/normalized/RemovedFieldsAndRecords; + public static final fun removeStaleFields-SxA4cEA (Lcom/apollographql/cache/normalized/ApolloStore;Lcom/apollographql/cache/normalized/api/MaxAgeProvider;J)Lcom/apollographql/cache/normalized/RemovedFieldsAndRecords; public static final fun removeStaleFields-SxA4cEA (Lcom/apollographql/cache/normalized/api/NormalizedCache;Lcom/apollographql/cache/normalized/api/MaxAgeProvider;J)Lcom/apollographql/cache/normalized/RemovedFieldsAndRecords; - public static synthetic fun removeStaleFields-SxA4cEA$default (Lcom/apollographql/cache/normalized/SimpleApolloStore;Lcom/apollographql/cache/normalized/api/MaxAgeProvider;JILjava/lang/Object;)Lcom/apollographql/cache/normalized/RemovedFieldsAndRecords; + public static synthetic fun removeStaleFields-SxA4cEA$default (Lcom/apollographql/cache/normalized/ApolloStore;Lcom/apollographql/cache/normalized/api/MaxAgeProvider;JILjava/lang/Object;)Lcom/apollographql/cache/normalized/RemovedFieldsAndRecords; public static synthetic fun removeStaleFields-SxA4cEA$default (Lcom/apollographql/cache/normalized/api/NormalizedCache;Lcom/apollographql/cache/normalized/api/MaxAgeProvider;JILjava/lang/Object;)Lcom/apollographql/cache/normalized/RemovedFieldsAndRecords; - public static final fun removeUnreachableRecords (Lcom/apollographql/cache/normalized/SimpleApolloStore;)Ljava/util/Set; + public static final fun removeUnreachableRecords (Lcom/apollographql/cache/normalized/ApolloStore;)Ljava/util/Set; public static final fun removeUnreachableRecords (Lcom/apollographql/cache/normalized/api/NormalizedCache;)Ljava/util/Set; } @@ -158,11 +191,11 @@ public final class com/apollographql/cache/normalized/NormalizedCache { public static final fun fetchFromCache (Lcom/apollographql/apollo/api/ApolloRequest$Builder;Z)Lcom/apollographql/apollo/api/ApolloRequest$Builder; public static final fun fetchPolicy (Lcom/apollographql/apollo/api/MutableExecutionOptions;Lcom/apollographql/cache/normalized/FetchPolicy;)Ljava/lang/Object; public static final fun fetchPolicyInterceptor (Lcom/apollographql/apollo/api/MutableExecutionOptions;Lcom/apollographql/apollo/interceptor/ApolloInterceptor;)Ljava/lang/Object; - public static final fun getApolloStore (Lcom/apollographql/apollo/ApolloClient;)Lcom/apollographql/cache/normalized/SimpleApolloStore; + public static final fun getApolloStore (Lcom/apollographql/apollo/ApolloClient;)Lcom/apollographql/cache/normalized/ApolloStore; public static final fun getCacheHeaders (Lcom/apollographql/apollo/api/ApolloResponse;)Lcom/apollographql/cache/normalized/api/CacheHeaders; public static final fun getCacheInfo (Lcom/apollographql/apollo/api/ApolloResponse;)Lcom/apollographql/cache/normalized/CacheInfo; public static final fun getFetchFromCache (Lcom/apollographql/apollo/api/ApolloRequest;)Z - public static final fun getStore (Lcom/apollographql/apollo/ApolloClient;)Lcom/apollographql/cache/normalized/SimpleApolloStore; + public static final fun getStore (Lcom/apollographql/apollo/ApolloClient;)Lcom/apollographql/cache/normalized/ApolloStore; public static final fun isFromCache (Lcom/apollographql/apollo/api/ApolloResponse;)Z public static final fun maxStale-HG0u8IE (Lcom/apollographql/apollo/api/MutableExecutionOptions;J)Ljava/lang/Object; public static final fun memoryCacheOnly (Lcom/apollographql/apollo/api/MutableExecutionOptions;Z)Ljava/lang/Object; @@ -184,39 +217,6 @@ public final class com/apollographql/cache/normalized/RemovedFieldsAndRecords { public final fun getRemovedRecords ()Ljava/util/Set; } -public final class com/apollographql/cache/normalized/SimpleApolloStore { - public fun (Lcom/apollographql/cache/normalized/CacheManager;Lcom/apollographql/apollo/api/CustomScalarAdapters;)V - public final fun accessCache (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public final fun clearAll ()Z - public final fun dispose ()V - public final fun dump ()Ljava/util/Map; - public final fun getCacheManager ()Lcom/apollographql/cache/normalized/CacheManager; - public final fun getChangedKeys ()Lkotlinx/coroutines/flow/SharedFlow; - public final fun getCustomScalarAdapters ()Lcom/apollographql/apollo/api/CustomScalarAdapters; - public final fun normalize-Hljz6HE (Lcom/apollographql/apollo/api/Executable;Ljava/util/Map;Ljava/lang/String;)Ljava/util/Map; - public static synthetic fun normalize-Hljz6HE$default (Lcom/apollographql/cache/normalized/SimpleApolloStore;Lcom/apollographql/apollo/api/Executable;Ljava/util/Map;Ljava/lang/String;ILjava/lang/Object;)Ljava/util/Map; - public final fun publish (Ljava/util/Set;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public final fun readFragment-0aEo43o (Lcom/apollographql/apollo/api/Fragment;Ljava/lang/String;Lcom/apollographql/cache/normalized/api/CacheHeaders;)Lcom/apollographql/cache/normalized/CacheManager$ReadResult; - public static synthetic fun readFragment-0aEo43o$default (Lcom/apollographql/cache/normalized/SimpleApolloStore;Lcom/apollographql/apollo/api/Fragment;Ljava/lang/String;Lcom/apollographql/cache/normalized/api/CacheHeaders;ILjava/lang/Object;)Lcom/apollographql/cache/normalized/CacheManager$ReadResult; - public final fun readOperation (Lcom/apollographql/apollo/api/Operation;Lcom/apollographql/cache/normalized/api/CacheHeaders;)Lcom/apollographql/apollo/api/ApolloResponse; - public static synthetic fun readOperation$default (Lcom/apollographql/cache/normalized/SimpleApolloStore;Lcom/apollographql/apollo/api/Operation;Lcom/apollographql/cache/normalized/api/CacheHeaders;ILjava/lang/Object;)Lcom/apollographql/apollo/api/ApolloResponse; - public final fun remove (Ljava/util/List;Z)I - public static synthetic fun remove$default (Lcom/apollographql/cache/normalized/SimpleApolloStore;Ljava/util/List;ZILjava/lang/Object;)I - public final fun remove-eNSUWrY (Ljava/lang/String;Z)Z - public static synthetic fun remove-eNSUWrY$default (Lcom/apollographql/cache/normalized/SimpleApolloStore;Ljava/lang/String;ZILjava/lang/Object;)Z - public final fun rollbackOptimisticUpdates (Ljava/util/UUID;)Ljava/util/Set; - public final fun trim (JF)J - public static synthetic fun trim$default (Lcom/apollographql/cache/normalized/SimpleApolloStore;JFILjava/lang/Object;)J - public final fun writeFragment-dEpVOtE (Lcom/apollographql/apollo/api/Fragment;Ljava/lang/String;Lcom/apollographql/apollo/api/Fragment$Data;Lcom/apollographql/cache/normalized/api/CacheHeaders;)Ljava/util/Set; - public static synthetic fun writeFragment-dEpVOtE$default (Lcom/apollographql/cache/normalized/SimpleApolloStore;Lcom/apollographql/apollo/api/Fragment;Ljava/lang/String;Lcom/apollographql/apollo/api/Fragment$Data;Lcom/apollographql/cache/normalized/api/CacheHeaders;ILjava/lang/Object;)Ljava/util/Set; - public final fun writeOperation (Lcom/apollographql/apollo/api/Operation;Lcom/apollographql/apollo/api/Operation$Data;Ljava/util/List;Lcom/apollographql/cache/normalized/api/CacheHeaders;)Ljava/util/Set; - public final fun writeOperation (Lcom/apollographql/apollo/api/Operation;Ljava/util/Map;Lcom/apollographql/cache/normalized/api/CacheHeaders;)Ljava/util/Set; - public static synthetic fun writeOperation$default (Lcom/apollographql/cache/normalized/SimpleApolloStore;Lcom/apollographql/apollo/api/Operation;Lcom/apollographql/apollo/api/Operation$Data;Ljava/util/List;Lcom/apollographql/cache/normalized/api/CacheHeaders;ILjava/lang/Object;)Ljava/util/Set; - public static synthetic fun writeOperation$default (Lcom/apollographql/cache/normalized/SimpleApolloStore;Lcom/apollographql/apollo/api/Operation;Ljava/util/Map;Lcom/apollographql/cache/normalized/api/CacheHeaders;ILjava/lang/Object;)Ljava/util/Set; - public final fun writeOptimisticUpdates (Lcom/apollographql/apollo/api/Operation;Lcom/apollographql/apollo/api/Operation$Data;Ljava/util/UUID;)Ljava/util/Set; - public final fun writeOptimisticUpdates-dEpVOtE (Lcom/apollographql/apollo/api/Fragment;Ljava/lang/String;Lcom/apollographql/apollo/api/Fragment$Data;Ljava/util/UUID;)Ljava/util/Set; -} - public final class com/apollographql/cache/normalized/VersionKt { public static final field VERSION Ljava/lang/String; } diff --git a/normalized-cache/api/normalized-cache.klib.api b/normalized-cache/api/normalized-cache.klib.api index eb69b497..91a89c6d 100644 --- a/normalized-cache/api/normalized-cache.klib.api +++ b/normalized-cache/api/normalized-cache.klib.api @@ -402,6 +402,35 @@ final class com.apollographql.cache.normalized.memory/MemoryCacheFactory : com.a final fun create(): com.apollographql.cache.normalized.memory/MemoryCache // com.apollographql.cache.normalized.memory/MemoryCacheFactory.create|create(){}[0] } +final class com.apollographql.cache.normalized/ApolloStore { // com.apollographql.cache.normalized/ApolloStore|null[0] + constructor (com.apollographql.cache.normalized/CacheManager, com.apollographql.apollo.api/CustomScalarAdapters) // com.apollographql.cache.normalized/ApolloStore.|(com.apollographql.cache.normalized.CacheManager;com.apollographql.apollo.api.CustomScalarAdapters){}[0] + + final val cacheManager // com.apollographql.cache.normalized/ApolloStore.cacheManager|{}cacheManager[0] + final fun (): com.apollographql.cache.normalized/CacheManager // com.apollographql.cache.normalized/ApolloStore.cacheManager.|(){}[0] + final val changedKeys // com.apollographql.cache.normalized/ApolloStore.changedKeys|{}changedKeys[0] + final fun (): kotlinx.coroutines.flow/SharedFlow> // com.apollographql.cache.normalized/ApolloStore.changedKeys.|(){}[0] + final val customScalarAdapters // com.apollographql.cache.normalized/ApolloStore.customScalarAdapters|{}customScalarAdapters[0] + final fun (): com.apollographql.apollo.api/CustomScalarAdapters // com.apollographql.cache.normalized/ApolloStore.customScalarAdapters.|(){}[0] + + final fun <#A1: com.apollographql.apollo.api/Executable.Data> normalize(com.apollographql.apollo.api/Executable<#A1>, kotlin.collections/Map, com.apollographql.cache.normalized.api/CacheKey = ...): kotlin.collections/Map // com.apollographql.cache.normalized/ApolloStore.normalize|normalize(com.apollographql.apollo.api.Executable<0:0>;kotlin.collections.Map;com.apollographql.cache.normalized.api.CacheKey){0§}[0] + final fun <#A1: com.apollographql.apollo.api/Fragment.Data> readFragment(com.apollographql.apollo.api/Fragment<#A1>, com.apollographql.cache.normalized.api/CacheKey, com.apollographql.cache.normalized.api/CacheHeaders = ...): com.apollographql.cache.normalized/CacheManager.ReadResult<#A1> // com.apollographql.cache.normalized/ApolloStore.readFragment|readFragment(com.apollographql.apollo.api.Fragment<0:0>;com.apollographql.cache.normalized.api.CacheKey;com.apollographql.cache.normalized.api.CacheHeaders){0§}[0] + final fun <#A1: com.apollographql.apollo.api/Fragment.Data> writeFragment(com.apollographql.apollo.api/Fragment<#A1>, com.apollographql.cache.normalized.api/CacheKey, #A1, com.apollographql.cache.normalized.api/CacheHeaders = ...): kotlin.collections/Set // com.apollographql.cache.normalized/ApolloStore.writeFragment|writeFragment(com.apollographql.apollo.api.Fragment<0:0>;com.apollographql.cache.normalized.api.CacheKey;0:0;com.apollographql.cache.normalized.api.CacheHeaders){0§}[0] + final fun <#A1: com.apollographql.apollo.api/Fragment.Data> writeOptimisticUpdates(com.apollographql.apollo.api/Fragment<#A1>, com.apollographql.cache.normalized.api/CacheKey, #A1, com.benasher44.uuid/Uuid): kotlin.collections/Set // com.apollographql.cache.normalized/ApolloStore.writeOptimisticUpdates|writeOptimisticUpdates(com.apollographql.apollo.api.Fragment<0:0>;com.apollographql.cache.normalized.api.CacheKey;0:0;com.benasher44.uuid.Uuid){0§}[0] + final fun <#A1: com.apollographql.apollo.api/Operation.Data> readOperation(com.apollographql.apollo.api/Operation<#A1>, com.apollographql.cache.normalized.api/CacheHeaders = ...): com.apollographql.apollo.api/ApolloResponse<#A1> // com.apollographql.cache.normalized/ApolloStore.readOperation|readOperation(com.apollographql.apollo.api.Operation<0:0>;com.apollographql.cache.normalized.api.CacheHeaders){0§}[0] + final fun <#A1: com.apollographql.apollo.api/Operation.Data> writeOperation(com.apollographql.apollo.api/Operation<#A1>, #A1, kotlin.collections/List? = ..., com.apollographql.cache.normalized.api/CacheHeaders = ...): kotlin.collections/Set // com.apollographql.cache.normalized/ApolloStore.writeOperation|writeOperation(com.apollographql.apollo.api.Operation<0:0>;0:0;kotlin.collections.List?;com.apollographql.cache.normalized.api.CacheHeaders){0§}[0] + final fun <#A1: com.apollographql.apollo.api/Operation.Data> writeOperation(com.apollographql.apollo.api/Operation<#A1>, kotlin.collections/Map, com.apollographql.cache.normalized.api/CacheHeaders = ...): kotlin.collections/Set // com.apollographql.cache.normalized/ApolloStore.writeOperation|writeOperation(com.apollographql.apollo.api.Operation<0:0>;kotlin.collections.Map;com.apollographql.cache.normalized.api.CacheHeaders){0§}[0] + final fun <#A1: com.apollographql.apollo.api/Operation.Data> writeOptimisticUpdates(com.apollographql.apollo.api/Operation<#A1>, #A1, com.benasher44.uuid/Uuid): kotlin.collections/Set // com.apollographql.cache.normalized/ApolloStore.writeOptimisticUpdates|writeOptimisticUpdates(com.apollographql.apollo.api.Operation<0:0>;0:0;com.benasher44.uuid.Uuid){0§}[0] + final fun <#A1: kotlin/Any?> accessCache(kotlin/Function1): #A1 // com.apollographql.cache.normalized/ApolloStore.accessCache|accessCache(kotlin.Function1){0§}[0] + final fun clearAll(): kotlin/Boolean // com.apollographql.cache.normalized/ApolloStore.clearAll|clearAll(){}[0] + final fun dispose() // com.apollographql.cache.normalized/ApolloStore.dispose|dispose(){}[0] + final fun dump(): kotlin.collections/Map, kotlin.collections/Map> // com.apollographql.cache.normalized/ApolloStore.dump|dump(){}[0] + final fun remove(com.apollographql.cache.normalized.api/CacheKey, kotlin/Boolean = ...): kotlin/Boolean // com.apollographql.cache.normalized/ApolloStore.remove|remove(com.apollographql.cache.normalized.api.CacheKey;kotlin.Boolean){}[0] + final fun remove(kotlin.collections/List, kotlin/Boolean = ...): kotlin/Int // com.apollographql.cache.normalized/ApolloStore.remove|remove(kotlin.collections.List;kotlin.Boolean){}[0] + final fun rollbackOptimisticUpdates(com.benasher44.uuid/Uuid): kotlin.collections/Set // com.apollographql.cache.normalized/ApolloStore.rollbackOptimisticUpdates|rollbackOptimisticUpdates(com.benasher44.uuid.Uuid){}[0] + final fun trim(kotlin/Long, kotlin/Float = ...): kotlin/Long // com.apollographql.cache.normalized/ApolloStore.trim|trim(kotlin.Long;kotlin.Float){}[0] + final suspend fun publish(kotlin.collections/Set) // com.apollographql.cache.normalized/ApolloStore.publish|publish(kotlin.collections.Set){}[0] +} + final class com.apollographql.cache.normalized/CacheInfo : com.apollographql.apollo.api/ExecutionContext.Element { // com.apollographql.cache.normalized/CacheInfo|null[0] final val cacheEndMillis // com.apollographql.cache.normalized/CacheInfo.cacheEndMillis|{}cacheEndMillis[0] final fun (): kotlin/Long // com.apollographql.cache.normalized/CacheInfo.cacheEndMillis.|(){}[0] @@ -470,35 +499,6 @@ final class com.apollographql.cache.normalized/RemovedFieldsAndRecords { // com. final fun (): kotlin.collections/Set // com.apollographql.cache.normalized/RemovedFieldsAndRecords.removedRecords.|(){}[0] } -final class com.apollographql.cache.normalized/SimpleApolloStore { // com.apollographql.cache.normalized/SimpleApolloStore|null[0] - constructor (com.apollographql.cache.normalized/CacheManager, com.apollographql.apollo.api/CustomScalarAdapters) // com.apollographql.cache.normalized/SimpleApolloStore.|(com.apollographql.cache.normalized.CacheManager;com.apollographql.apollo.api.CustomScalarAdapters){}[0] - - final val cacheManager // com.apollographql.cache.normalized/SimpleApolloStore.cacheManager|{}cacheManager[0] - final fun (): com.apollographql.cache.normalized/CacheManager // com.apollographql.cache.normalized/SimpleApolloStore.cacheManager.|(){}[0] - final val changedKeys // com.apollographql.cache.normalized/SimpleApolloStore.changedKeys|{}changedKeys[0] - final fun (): kotlinx.coroutines.flow/SharedFlow> // com.apollographql.cache.normalized/SimpleApolloStore.changedKeys.|(){}[0] - final val customScalarAdapters // com.apollographql.cache.normalized/SimpleApolloStore.customScalarAdapters|{}customScalarAdapters[0] - final fun (): com.apollographql.apollo.api/CustomScalarAdapters // com.apollographql.cache.normalized/SimpleApolloStore.customScalarAdapters.|(){}[0] - - final fun <#A1: com.apollographql.apollo.api/Executable.Data> normalize(com.apollographql.apollo.api/Executable<#A1>, kotlin.collections/Map, com.apollographql.cache.normalized.api/CacheKey = ...): kotlin.collections/Map // com.apollographql.cache.normalized/SimpleApolloStore.normalize|normalize(com.apollographql.apollo.api.Executable<0:0>;kotlin.collections.Map;com.apollographql.cache.normalized.api.CacheKey){0§}[0] - final fun <#A1: com.apollographql.apollo.api/Fragment.Data> readFragment(com.apollographql.apollo.api/Fragment<#A1>, com.apollographql.cache.normalized.api/CacheKey, com.apollographql.cache.normalized.api/CacheHeaders = ...): com.apollographql.cache.normalized/CacheManager.ReadResult<#A1> // com.apollographql.cache.normalized/SimpleApolloStore.readFragment|readFragment(com.apollographql.apollo.api.Fragment<0:0>;com.apollographql.cache.normalized.api.CacheKey;com.apollographql.cache.normalized.api.CacheHeaders){0§}[0] - final fun <#A1: com.apollographql.apollo.api/Fragment.Data> writeFragment(com.apollographql.apollo.api/Fragment<#A1>, com.apollographql.cache.normalized.api/CacheKey, #A1, com.apollographql.cache.normalized.api/CacheHeaders = ...): kotlin.collections/Set // com.apollographql.cache.normalized/SimpleApolloStore.writeFragment|writeFragment(com.apollographql.apollo.api.Fragment<0:0>;com.apollographql.cache.normalized.api.CacheKey;0:0;com.apollographql.cache.normalized.api.CacheHeaders){0§}[0] - final fun <#A1: com.apollographql.apollo.api/Fragment.Data> writeOptimisticUpdates(com.apollographql.apollo.api/Fragment<#A1>, com.apollographql.cache.normalized.api/CacheKey, #A1, com.benasher44.uuid/Uuid): kotlin.collections/Set // com.apollographql.cache.normalized/SimpleApolloStore.writeOptimisticUpdates|writeOptimisticUpdates(com.apollographql.apollo.api.Fragment<0:0>;com.apollographql.cache.normalized.api.CacheKey;0:0;com.benasher44.uuid.Uuid){0§}[0] - final fun <#A1: com.apollographql.apollo.api/Operation.Data> readOperation(com.apollographql.apollo.api/Operation<#A1>, com.apollographql.cache.normalized.api/CacheHeaders = ...): com.apollographql.apollo.api/ApolloResponse<#A1> // com.apollographql.cache.normalized/SimpleApolloStore.readOperation|readOperation(com.apollographql.apollo.api.Operation<0:0>;com.apollographql.cache.normalized.api.CacheHeaders){0§}[0] - final fun <#A1: com.apollographql.apollo.api/Operation.Data> writeOperation(com.apollographql.apollo.api/Operation<#A1>, #A1, kotlin.collections/List? = ..., com.apollographql.cache.normalized.api/CacheHeaders = ...): kotlin.collections/Set // com.apollographql.cache.normalized/SimpleApolloStore.writeOperation|writeOperation(com.apollographql.apollo.api.Operation<0:0>;0:0;kotlin.collections.List?;com.apollographql.cache.normalized.api.CacheHeaders){0§}[0] - final fun <#A1: com.apollographql.apollo.api/Operation.Data> writeOperation(com.apollographql.apollo.api/Operation<#A1>, kotlin.collections/Map, com.apollographql.cache.normalized.api/CacheHeaders = ...): kotlin.collections/Set // com.apollographql.cache.normalized/SimpleApolloStore.writeOperation|writeOperation(com.apollographql.apollo.api.Operation<0:0>;kotlin.collections.Map;com.apollographql.cache.normalized.api.CacheHeaders){0§}[0] - final fun <#A1: com.apollographql.apollo.api/Operation.Data> writeOptimisticUpdates(com.apollographql.apollo.api/Operation<#A1>, #A1, com.benasher44.uuid/Uuid): kotlin.collections/Set // com.apollographql.cache.normalized/SimpleApolloStore.writeOptimisticUpdates|writeOptimisticUpdates(com.apollographql.apollo.api.Operation<0:0>;0:0;com.benasher44.uuid.Uuid){0§}[0] - final fun <#A1: kotlin/Any?> accessCache(kotlin/Function1): #A1 // com.apollographql.cache.normalized/SimpleApolloStore.accessCache|accessCache(kotlin.Function1){0§}[0] - final fun clearAll(): kotlin/Boolean // com.apollographql.cache.normalized/SimpleApolloStore.clearAll|clearAll(){}[0] - final fun dispose() // com.apollographql.cache.normalized/SimpleApolloStore.dispose|dispose(){}[0] - final fun dump(): kotlin.collections/Map, kotlin.collections/Map> // com.apollographql.cache.normalized/SimpleApolloStore.dump|dump(){}[0] - final fun remove(com.apollographql.cache.normalized.api/CacheKey, kotlin/Boolean = ...): kotlin/Boolean // com.apollographql.cache.normalized/SimpleApolloStore.remove|remove(com.apollographql.cache.normalized.api.CacheKey;kotlin.Boolean){}[0] - final fun remove(kotlin.collections/List, kotlin/Boolean = ...): kotlin/Int // com.apollographql.cache.normalized/SimpleApolloStore.remove|remove(kotlin.collections.List;kotlin.Boolean){}[0] - final fun rollbackOptimisticUpdates(com.benasher44.uuid/Uuid): kotlin.collections/Set // com.apollographql.cache.normalized/SimpleApolloStore.rollbackOptimisticUpdates|rollbackOptimisticUpdates(com.benasher44.uuid.Uuid){}[0] - final fun trim(kotlin/Long, kotlin/Float = ...): kotlin/Long // com.apollographql.cache.normalized/SimpleApolloStore.trim|trim(kotlin.Long;kotlin.Float){}[0] - final suspend fun publish(kotlin.collections/Set) // com.apollographql.cache.normalized/SimpleApolloStore.publish|publish(kotlin.collections.Set){}[0] -} - final value class com.apollographql.cache.normalized.api/CacheKey { // com.apollographql.cache.normalized.api/CacheKey|null[0] constructor (kotlin/String) // com.apollographql.cache.normalized.api/CacheKey.|(kotlin.String){}[0] constructor (kotlin/String, kotlin.collections/List) // com.apollographql.cache.normalized.api/CacheKey.|(kotlin.String;kotlin.collections.List){}[0] @@ -586,7 +586,7 @@ final val com.apollographql.cache.normalized/NetworkFirstInterceptor // com.apol final val com.apollographql.cache.normalized/NetworkOnlyInterceptor // com.apollographql.cache.normalized/NetworkOnlyInterceptor|{}NetworkOnlyInterceptor[0] final fun (): com.apollographql.apollo.interceptor/ApolloInterceptor // com.apollographql.cache.normalized/NetworkOnlyInterceptor.|(){}[0] final val com.apollographql.cache.normalized/apolloStore // com.apollographql.cache.normalized/apolloStore|@com.apollographql.apollo.ApolloClient{}apolloStore[0] - final fun (com.apollographql.apollo/ApolloClient).(): com.apollographql.cache.normalized/SimpleApolloStore // com.apollographql.cache.normalized/apolloStore.|@com.apollographql.apollo.ApolloClient(){}[0] + final fun (com.apollographql.apollo/ApolloClient).(): com.apollographql.cache.normalized/ApolloStore // com.apollographql.cache.normalized/apolloStore.|@com.apollographql.apollo.ApolloClient(){}[0] final val com.apollographql.cache.normalized/cacheHeaders // com.apollographql.cache.normalized/cacheHeaders|@com.apollographql.apollo.api.ApolloResponse<0:0>{0§}cacheHeaders[0] final fun <#A1: com.apollographql.apollo.api/Operation.Data> (com.apollographql.apollo.api/ApolloResponse<#A1>).(): com.apollographql.cache.normalized.api/CacheHeaders // com.apollographql.cache.normalized/cacheHeaders.|@com.apollographql.apollo.api.ApolloResponse<0:0>(){0§}[0] final val com.apollographql.cache.normalized/cacheInfo // com.apollographql.cache.normalized/cacheInfo|@com.apollographql.apollo.api.ApolloResponse<0:0>{0§}cacheInfo[0] @@ -598,7 +598,7 @@ final val com.apollographql.cache.normalized/fetchFromCache // com.apollographql final val com.apollographql.cache.normalized/isFromCache // com.apollographql.cache.normalized/isFromCache|@com.apollographql.apollo.api.ApolloResponse<0:0>{0§}isFromCache[0] final fun <#A1: com.apollographql.apollo.api/Operation.Data> (com.apollographql.apollo.api/ApolloResponse<#A1>).(): kotlin/Boolean // com.apollographql.cache.normalized/isFromCache.|@com.apollographql.apollo.api.ApolloResponse<0:0>(){0§}[0] final val com.apollographql.cache.normalized/store // com.apollographql.cache.normalized/store|@com.apollographql.apollo.ApolloClient{}store[0] - final fun (com.apollographql.apollo/ApolloClient).(): com.apollographql.cache.normalized/SimpleApolloStore // com.apollographql.cache.normalized/store.|@com.apollographql.apollo.ApolloClient(){}[0] + final fun (com.apollographql.apollo/ApolloClient).(): com.apollographql.cache.normalized/ApolloStore // com.apollographql.cache.normalized/store.|@com.apollographql.apollo.ApolloClient(){}[0] final fun (com.apollographql.apollo/ApolloClient.Builder).com.apollographql.cache.normalized/cacheManager(com.apollographql.cache.normalized/CacheManager, kotlin/Boolean = ...): com.apollographql.apollo/ApolloClient.Builder // com.apollographql.cache.normalized/cacheManager|cacheManager@com.apollographql.apollo.ApolloClient.Builder(com.apollographql.cache.normalized.CacheManager;kotlin.Boolean){}[0] final fun (com.apollographql.apollo/ApolloClient.Builder).com.apollographql.cache.normalized/logCacheMisses(kotlin/Function1 = ...): com.apollographql.apollo/ApolloClient.Builder // com.apollographql.cache.normalized/logCacheMisses|logCacheMisses@com.apollographql.apollo.ApolloClient.Builder(kotlin.Function1){}[0] @@ -612,10 +612,10 @@ final fun (com.apollographql.cache.normalized.api/Record).com.apollographql.cach final fun (com.apollographql.cache.normalized.api/Record).com.apollographql.cache.normalized.api/receivedDate(kotlin/String): kotlin/Long? // com.apollographql.cache.normalized.api/receivedDate|receivedDate@com.apollographql.cache.normalized.api.Record(kotlin.String){}[0] final fun (com.apollographql.cache.normalized.api/Record).com.apollographql.cache.normalized.api/withDates(kotlin/String?, kotlin/String?): com.apollographql.cache.normalized.api/Record // com.apollographql.cache.normalized.api/withDates|withDates@com.apollographql.cache.normalized.api.Record(kotlin.String?;kotlin.String?){}[0] final fun (com.apollographql.cache.normalized.api/ResolverContext).com.apollographql.cache.normalized.api/getFieldKey(): kotlin/String // com.apollographql.cache.normalized.api/getFieldKey|getFieldKey@com.apollographql.cache.normalized.api.ResolverContext(){}[0] -final fun (com.apollographql.cache.normalized/SimpleApolloStore).com.apollographql.cache.normalized/garbageCollect(com.apollographql.cache.normalized.api/MaxAgeProvider, kotlin.time/Duration = ...): com.apollographql.cache.normalized/GarbageCollectResult // com.apollographql.cache.normalized/garbageCollect|garbageCollect@com.apollographql.cache.normalized.SimpleApolloStore(com.apollographql.cache.normalized.api.MaxAgeProvider;kotlin.time.Duration){}[0] -final fun (com.apollographql.cache.normalized/SimpleApolloStore).com.apollographql.cache.normalized/removeDanglingReferences(): com.apollographql.cache.normalized/RemovedFieldsAndRecords // com.apollographql.cache.normalized/removeDanglingReferences|removeDanglingReferences@com.apollographql.cache.normalized.SimpleApolloStore(){}[0] -final fun (com.apollographql.cache.normalized/SimpleApolloStore).com.apollographql.cache.normalized/removeStaleFields(com.apollographql.cache.normalized.api/MaxAgeProvider, kotlin.time/Duration = ...): com.apollographql.cache.normalized/RemovedFieldsAndRecords // com.apollographql.cache.normalized/removeStaleFields|removeStaleFields@com.apollographql.cache.normalized.SimpleApolloStore(com.apollographql.cache.normalized.api.MaxAgeProvider;kotlin.time.Duration){}[0] -final fun (com.apollographql.cache.normalized/SimpleApolloStore).com.apollographql.cache.normalized/removeUnreachableRecords(): kotlin.collections/Set // com.apollographql.cache.normalized/removeUnreachableRecords|removeUnreachableRecords@com.apollographql.cache.normalized.SimpleApolloStore(){}[0] +final fun (com.apollographql.cache.normalized/ApolloStore).com.apollographql.cache.normalized/garbageCollect(com.apollographql.cache.normalized.api/MaxAgeProvider, kotlin.time/Duration = ...): com.apollographql.cache.normalized/GarbageCollectResult // com.apollographql.cache.normalized/garbageCollect|garbageCollect@com.apollographql.cache.normalized.ApolloStore(com.apollographql.cache.normalized.api.MaxAgeProvider;kotlin.time.Duration){}[0] +final fun (com.apollographql.cache.normalized/ApolloStore).com.apollographql.cache.normalized/removeDanglingReferences(): com.apollographql.cache.normalized/RemovedFieldsAndRecords // com.apollographql.cache.normalized/removeDanglingReferences|removeDanglingReferences@com.apollographql.cache.normalized.ApolloStore(){}[0] +final fun (com.apollographql.cache.normalized/ApolloStore).com.apollographql.cache.normalized/removeStaleFields(com.apollographql.cache.normalized.api/MaxAgeProvider, kotlin.time/Duration = ...): com.apollographql.cache.normalized/RemovedFieldsAndRecords // com.apollographql.cache.normalized/removeStaleFields|removeStaleFields@com.apollographql.cache.normalized.ApolloStore(com.apollographql.cache.normalized.api.MaxAgeProvider;kotlin.time.Duration){}[0] +final fun (com.apollographql.cache.normalized/ApolloStore).com.apollographql.cache.normalized/removeUnreachableRecords(): kotlin.collections/Set // com.apollographql.cache.normalized/removeUnreachableRecords|removeUnreachableRecords@com.apollographql.cache.normalized.ApolloStore(){}[0] final fun (kotlin.collections/Collection?).com.apollographql.cache.normalized.api/dependentKeys(): kotlin.collections/Set // com.apollographql.cache.normalized.api/dependentKeys|dependentKeys@kotlin.collections.Collection?(){}[0] final fun (kotlin.collections/Map).com.apollographql.cache.normalized/getReachableCacheKeys(): kotlin.collections/Set // com.apollographql.cache.normalized/getReachableCacheKeys|getReachableCacheKeys@kotlin.collections.Map(){}[0] final fun <#A: com.apollographql.apollo.api/Executable.Data> (#A).com.apollographql.cache.normalized.api/withErrors(com.apollographql.apollo.api/Executable<#A>, kotlin.collections/List?, com.apollographql.apollo.api/CustomScalarAdapters = ...): kotlin.collections/Map // com.apollographql.cache.normalized.api/withErrors|withErrors@0:0(com.apollographql.apollo.api.Executable<0:0>;kotlin.collections.List?;com.apollographql.apollo.api.CustomScalarAdapters){0§}[0] diff --git a/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/SimpleApolloStore.kt b/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/ApolloStore.kt similarity index 99% rename from normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/SimpleApolloStore.kt rename to normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/ApolloStore.kt index 77388fd0..540f0264 100644 --- a/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/SimpleApolloStore.kt +++ b/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/ApolloStore.kt @@ -19,7 +19,7 @@ import kotlin.reflect.KClass /** * A wrapper around [CacheManager] that provides a simplified API for reading and writing data. */ -class SimpleApolloStore( +class ApolloStore( val cacheManager: CacheManager, val customScalarAdapters: CustomScalarAdapters, ) { diff --git a/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/ClientCacheExtensions.kt b/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/ClientCacheExtensions.kt index a635135c..d7c09de1 100644 --- a/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/ClientCacheExtensions.kt +++ b/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/ClientCacheExtensions.kt @@ -223,13 +223,13 @@ internal fun ApolloCall.watchInternal(data: D?): Flow { +fun ApolloStore.removeUnreachableRecords(): Set { return accessCache { cache -> cache.removeUnreachableRecords() } @@ -177,7 +177,7 @@ private fun NormalizedCache.removeStaleFields( * Remove all stale fields in the store. * @see removeStaleFields */ -fun SimpleApolloStore.removeStaleFields( +fun ApolloStore.removeStaleFields( maxAgeProvider: MaxAgeProvider, maxStale: Duration = Duration.ZERO, ): RemovedFieldsAndRecords { @@ -242,7 +242,7 @@ private fun NormalizedCache.removeDanglingReferences(allRecords: MutableMap cache.removeDanglingReferences() } @@ -308,7 +308,7 @@ fun NormalizedCache.garbageCollect( * Perform garbage collection on the store. * @see garbageCollect */ -fun SimpleApolloStore.garbageCollect( +fun ApolloStore.garbageCollect( maxAgeProvider: MaxAgeProvider, maxStale: Duration = Duration.ZERO, ): GarbageCollectResult { From 768ac9c3cab1dbbff9282746e7c5979e6870d00d Mon Sep 17 00:00:00 2001 From: BoD Date: Fri, 25 Apr 2025 15:15:35 +0200 Subject: [PATCH 06/11] Rename .store -> .apolloStore --- normalized-cache/api/normalized-cache.api | 1 - normalized-cache/api/normalized-cache.klib.api | 2 -- .../cache/normalized/ClientCacheExtensions.kt | 4 ---- .../ClientAndServerSideCacheControlTest.kt | 8 ++++---- .../kotlin/ClientSideCacheControlTest.kt | 18 +++++++++--------- .../src/commonTest/kotlin/DoNotStoreTest.kt | 8 ++++---- .../kotlin/ServerSideCacheControlTest.kt | 4 ++-- .../src/commonTest/kotlin/test/IncludeTest.kt | 4 ++-- .../kotlin/test/DeferNormalizedCacheTest.kt | 4 ++-- .../kotlin/DanglingReferencesTest.kt | 6 +++--- .../commonTest/kotlin/GarbageCollectTest.kt | 4 ++-- .../kotlin/ReachableCacheKeysTest.kt | 4 ++-- .../src/commonTest/kotlin/StaleFieldsTest.kt | 15 ++++++++------- .../kotlin/com/example/SqlNormalizationTest.kt | 6 +++--- .../FragmentNormalizerTest.kt | 8 ++++---- .../src/commonTest/kotlin/EmbedTest.kt | 6 +++--- .../kotlin/test/CachePartialResultTest.kt | 12 ++++++------ 17 files changed, 54 insertions(+), 60 deletions(-) diff --git a/normalized-cache/api/normalized-cache.api b/normalized-cache/api/normalized-cache.api index 112d3ac5..39591301 100644 --- a/normalized-cache/api/normalized-cache.api +++ b/normalized-cache/api/normalized-cache.api @@ -195,7 +195,6 @@ public final class com/apollographql/cache/normalized/NormalizedCache { public static final fun getCacheHeaders (Lcom/apollographql/apollo/api/ApolloResponse;)Lcom/apollographql/cache/normalized/api/CacheHeaders; public static final fun getCacheInfo (Lcom/apollographql/apollo/api/ApolloResponse;)Lcom/apollographql/cache/normalized/CacheInfo; public static final fun getFetchFromCache (Lcom/apollographql/apollo/api/ApolloRequest;)Z - public static final fun getStore (Lcom/apollographql/apollo/ApolloClient;)Lcom/apollographql/cache/normalized/ApolloStore; public static final fun isFromCache (Lcom/apollographql/apollo/api/ApolloResponse;)Z public static final fun maxStale-HG0u8IE (Lcom/apollographql/apollo/api/MutableExecutionOptions;J)Ljava/lang/Object; public static final fun memoryCacheOnly (Lcom/apollographql/apollo/api/MutableExecutionOptions;Z)Ljava/lang/Object; diff --git a/normalized-cache/api/normalized-cache.klib.api b/normalized-cache/api/normalized-cache.klib.api index 91a89c6d..817e7c28 100644 --- a/normalized-cache/api/normalized-cache.klib.api +++ b/normalized-cache/api/normalized-cache.klib.api @@ -597,8 +597,6 @@ final val com.apollographql.cache.normalized/fetchFromCache // com.apollographql final fun <#A1: com.apollographql.apollo.api/Operation.Data> (com.apollographql.apollo.api/ApolloRequest<#A1>).(): kotlin/Boolean // com.apollographql.cache.normalized/fetchFromCache.|@com.apollographql.apollo.api.ApolloRequest<0:0>(){0§}[0] final val com.apollographql.cache.normalized/isFromCache // com.apollographql.cache.normalized/isFromCache|@com.apollographql.apollo.api.ApolloResponse<0:0>{0§}isFromCache[0] final fun <#A1: com.apollographql.apollo.api/Operation.Data> (com.apollographql.apollo.api/ApolloResponse<#A1>).(): kotlin/Boolean // com.apollographql.cache.normalized/isFromCache.|@com.apollographql.apollo.api.ApolloResponse<0:0>(){0§}[0] -final val com.apollographql.cache.normalized/store // com.apollographql.cache.normalized/store|@com.apollographql.apollo.ApolloClient{}store[0] - final fun (com.apollographql.apollo/ApolloClient).(): com.apollographql.cache.normalized/ApolloStore // com.apollographql.cache.normalized/store.|@com.apollographql.apollo.ApolloClient(){}[0] final fun (com.apollographql.apollo/ApolloClient.Builder).com.apollographql.cache.normalized/cacheManager(com.apollographql.cache.normalized/CacheManager, kotlin/Boolean = ...): com.apollographql.apollo/ApolloClient.Builder // com.apollographql.cache.normalized/cacheManager|cacheManager@com.apollographql.apollo.ApolloClient.Builder(com.apollographql.cache.normalized.CacheManager;kotlin.Boolean){}[0] final fun (com.apollographql.apollo/ApolloClient.Builder).com.apollographql.cache.normalized/logCacheMisses(kotlin/Function1 = ...): com.apollographql.apollo/ApolloClient.Builder // com.apollographql.cache.normalized/logCacheMisses|logCacheMisses@com.apollographql.apollo.ApolloClient.Builder(kotlin.Function1){}[0] diff --git a/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/ClientCacheExtensions.kt b/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/ClientCacheExtensions.kt index d7c09de1..2c677baa 100644 --- a/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/ClientCacheExtensions.kt +++ b/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/ClientCacheExtensions.kt @@ -222,11 +222,7 @@ internal fun ApolloCall.watchInternal(data: D?): Flow - apolloClient.store.clearAll() + apolloClient.apolloStore.clearAll() val networkResponse = apolloClient.query(GetUserQuery()) .fetchPolicy(FetchPolicy.NetworkOnly) .execute() @@ -195,7 +195,7 @@ class DoNotStoreTest { ) .build() .use { apolloClient -> - apolloClient.store.clearAll() + apolloClient.apolloStore.clearAll() val networkResponse = apolloClient.mutation(SignInMutation("scott", "tiger")) .fetchPolicy(FetchPolicy.NetworkOnly) .execute() @@ -221,7 +221,7 @@ class DoNotStoreTest { networkResponse.data ) - apolloClient.store.accessCache { cache -> + apolloClient.apolloStore.accessCache { cache -> val authRecord = cache.loadRecord(CacheKey.MUTATION_ROOT.append("auth"), CacheHeaders.NONE)!! // No password in field key assertContentEquals(listOf("signIn"), authRecord.fields.keys) diff --git a/tests/cache-control/src/commonTest/kotlin/ServerSideCacheControlTest.kt b/tests/cache-control/src/commonTest/kotlin/ServerSideCacheControlTest.kt index 241f10e2..e3dc07ee 100644 --- a/tests/cache-control/src/commonTest/kotlin/ServerSideCacheControlTest.kt +++ b/tests/cache-control/src/commonTest/kotlin/ServerSideCacheControlTest.kt @@ -6,12 +6,12 @@ import com.apollographql.apollo.exception.CacheMissException import com.apollographql.cache.normalized.FetchPolicy import com.apollographql.cache.normalized.api.CacheControlCacheResolver import com.apollographql.cache.normalized.api.NormalizedCacheFactory +import com.apollographql.cache.normalized.apolloStore import com.apollographql.cache.normalized.fetchPolicy import com.apollographql.cache.normalized.maxStale import com.apollographql.cache.normalized.memory.MemoryCacheFactory import com.apollographql.cache.normalized.normalizedCache import com.apollographql.cache.normalized.sql.SqlNormalizedCacheFactory -import com.apollographql.cache.normalized.store import com.apollographql.cache.normalized.storeExpirationDate import com.apollographql.cache.normalized.testing.runTest import com.apollographql.mockserver.MockResponse @@ -48,7 +48,7 @@ class ServerSideCacheControlTest { .storeExpirationDate(true) .serverUrl(mockServer.url()) .build() - client.store.clearAll() + client.apolloStore.clearAll() val query = GetUserQuery() val data = """ diff --git a/tests/cache-variables-arguments/src/commonTest/kotlin/test/IncludeTest.kt b/tests/cache-variables-arguments/src/commonTest/kotlin/test/IncludeTest.kt index 084597a1..7fe5b2ee 100644 --- a/tests/cache-variables-arguments/src/commonTest/kotlin/test/IncludeTest.kt +++ b/tests/cache-variables-arguments/src/commonTest/kotlin/test/IncludeTest.kt @@ -3,10 +3,10 @@ package test import cache.include.GetUserQuery import com.apollographql.apollo.ApolloClient import com.apollographql.cache.normalized.FetchPolicy +import com.apollographql.cache.normalized.apolloStore import com.apollographql.cache.normalized.fetchPolicy import com.apollographql.cache.normalized.memory.MemoryCacheFactory import com.apollographql.cache.normalized.normalizedCache -import com.apollographql.cache.normalized.store import com.apollographql.cache.normalized.testing.runTest import kotlin.test.Test import kotlin.test.assertEquals @@ -25,7 +25,7 @@ class IncludeTest { user = GetUserQuery.User(__typename = "User", id = "42", userDetails = null) ) - client.store.writeOperation(operation, data) + client.apolloStore.writeOperation(operation, data) val response = client.query(operation).fetchPolicy(FetchPolicy.CacheOnly).execute() diff --git a/tests/defer/src/commonTest/kotlin/test/DeferNormalizedCacheTest.kt b/tests/defer/src/commonTest/kotlin/test/DeferNormalizedCacheTest.kt index f10904b2..e19b4807 100644 --- a/tests/defer/src/commonTest/kotlin/test/DeferNormalizedCacheTest.kt +++ b/tests/defer/src/commonTest/kotlin/test/DeferNormalizedCacheTest.kt @@ -15,11 +15,11 @@ import com.apollographql.cache.normalized.CacheManager import com.apollographql.cache.normalized.FetchPolicy import com.apollographql.cache.normalized.api.CacheHeaders import com.apollographql.cache.normalized.api.CacheKey +import com.apollographql.cache.normalized.apolloStore import com.apollographql.cache.normalized.cacheManager import com.apollographql.cache.normalized.fetchPolicy import com.apollographql.cache.normalized.memory.MemoryCacheFactory import com.apollographql.cache.normalized.optimisticUpdates -import com.apollographql.cache.normalized.store import com.apollographql.cache.normalized.testing.Platform import com.apollographql.cache.normalized.testing.append import com.apollographql.cache.normalized.testing.keyToString @@ -543,7 +543,7 @@ class DeferNormalizedCacheTest { val multipartBody = mockServer.enqueueMultipart("application/json") multipartBody.enqueuePart(jsonList[0].encodeUtf8(), false) val recordFields = apolloClient.query(SimpleDeferQuery()).fetchPolicy(FetchPolicy.NetworkOnly).toFlow().map { - apolloClient.store.accessCache { it.loadRecord(CacheKey("computers").append("0"), CacheHeaders.NONE)!!.fields }.also { + apolloClient.apolloStore.accessCache { it.loadRecord(CacheKey("computers").append("0"), CacheHeaders.NONE)!!.fields }.also { multipartBody.enqueuePart(jsonList[1].encodeUtf8(), true) } }.toList() diff --git a/tests/garbage-collection/src/commonTest/kotlin/DanglingReferencesTest.kt b/tests/garbage-collection/src/commonTest/kotlin/DanglingReferencesTest.kt index b45fa106..85cae628 100644 --- a/tests/garbage-collection/src/commonTest/kotlin/DanglingReferencesTest.kt +++ b/tests/garbage-collection/src/commonTest/kotlin/DanglingReferencesTest.kt @@ -5,12 +5,12 @@ import com.apollographql.cache.normalized.CacheManager import com.apollographql.cache.normalized.FetchPolicy import com.apollographql.cache.normalized.allRecords import com.apollographql.cache.normalized.api.CacheKey +import com.apollographql.cache.normalized.apolloStore import com.apollographql.cache.normalized.cacheManager import com.apollographql.cache.normalized.fetchPolicy import com.apollographql.cache.normalized.memory.MemoryCacheFactory import com.apollographql.cache.normalized.removeDanglingReferences import com.apollographql.cache.normalized.sql.SqlNormalizedCacheFactory -import com.apollographql.cache.normalized.store import com.apollographql.cache.normalized.testing.append import com.apollographql.cache.normalized.testing.fieldKey import com.apollographql.cache.normalized.testing.runTest @@ -53,7 +53,7 @@ class DanglingReferencesTest { // Remove User 1, now Repository 0.starGazers is a dangling reference cacheManager.remove(CacheKey("User:1"), cascade = false) - val removedFieldsAndRecords = apolloClient.store.removeDanglingReferences() + val removedFieldsAndRecords = apolloClient.apolloStore.removeDanglingReferences() assertEquals( setOf(CacheKey("Repository:0").fieldKey("starGazers")), removedFieldsAndRecords.removedFields @@ -97,7 +97,7 @@ class DanglingReferencesTest { // thus (QUERY_ROOT).metaProjects is a dangling reference // thus QUERY_ROOT is empty and removed cacheManager.remove(CacheKey("User:0"), cascade = false) - val removedFieldsAndRecords = apolloClient.store.removeDanglingReferences() + val removedFieldsAndRecords = apolloClient.apolloStore.removeDanglingReferences() assertEquals( setOf( CacheKey("metaProjects").append("0", "0", "type").fieldKey("owners"), diff --git a/tests/garbage-collection/src/commonTest/kotlin/GarbageCollectTest.kt b/tests/garbage-collection/src/commonTest/kotlin/GarbageCollectTest.kt index badbe229..8388cfc0 100644 --- a/tests/garbage-collection/src/commonTest/kotlin/GarbageCollectTest.kt +++ b/tests/garbage-collection/src/commonTest/kotlin/GarbageCollectTest.kt @@ -6,13 +6,13 @@ import com.apollographql.cache.normalized.FetchPolicy import com.apollographql.cache.normalized.allRecords import com.apollographql.cache.normalized.api.CacheKey import com.apollographql.cache.normalized.api.SchemaCoordinatesMaxAgeProvider +import com.apollographql.cache.normalized.apolloStore import com.apollographql.cache.normalized.cacheHeaders import com.apollographql.cache.normalized.cacheManager import com.apollographql.cache.normalized.fetchPolicy import com.apollographql.cache.normalized.garbageCollect import com.apollographql.cache.normalized.memory.MemoryCacheFactory import com.apollographql.cache.normalized.sql.SqlNormalizedCacheFactory -import com.apollographql.cache.normalized.store import com.apollographql.cache.normalized.testing.append import com.apollographql.cache.normalized.testing.fieldKey import com.apollographql.cache.normalized.testing.runTest @@ -59,7 +59,7 @@ class GarbageCollectTest { Cache.maxAges, defaultMaxAge = 120.seconds, ) - val garbageCollectResult = apolloClient.store.garbageCollect(maxAgeProvider) + val garbageCollectResult = apolloClient.apolloStore.garbageCollect(maxAgeProvider) assertEquals( setOf( CacheKey("metaProjects").append("0", "0", "type").fieldKey("owners"), diff --git a/tests/garbage-collection/src/commonTest/kotlin/ReachableCacheKeysTest.kt b/tests/garbage-collection/src/commonTest/kotlin/ReachableCacheKeysTest.kt index c69fda87..be7b2a7b 100644 --- a/tests/garbage-collection/src/commonTest/kotlin/ReachableCacheKeysTest.kt +++ b/tests/garbage-collection/src/commonTest/kotlin/ReachableCacheKeysTest.kt @@ -5,13 +5,13 @@ import com.apollographql.cache.normalized.CacheManager import com.apollographql.cache.normalized.FetchPolicy import com.apollographql.cache.normalized.allRecords import com.apollographql.cache.normalized.api.CacheKey +import com.apollographql.cache.normalized.apolloStore import com.apollographql.cache.normalized.cacheManager import com.apollographql.cache.normalized.fetchPolicy import com.apollographql.cache.normalized.getReachableCacheKeys import com.apollographql.cache.normalized.memory.MemoryCacheFactory import com.apollographql.cache.normalized.removeUnreachableRecords import com.apollographql.cache.normalized.sql.SqlNormalizedCacheFactory -import com.apollographql.cache.normalized.store import com.apollographql.cache.normalized.storeReceivedDate import com.apollographql.cache.normalized.testing.runTest import com.apollographql.mockserver.MockServer @@ -211,7 +211,7 @@ class ReachableCacheKeysTest { ) // Remove unreachable records, should remove Repositories 5, 6, and 500 - val removedKeys = apolloClient.store.removeUnreachableRecords() + val removedKeys = apolloClient.apolloStore.removeUnreachableRecords() assertEquals( setOf( CacheKey("QUERY_ROOT"), diff --git a/tests/garbage-collection/src/commonTest/kotlin/StaleFieldsTest.kt b/tests/garbage-collection/src/commonTest/kotlin/StaleFieldsTest.kt index 4a92960a..c06f1058 100644 --- a/tests/garbage-collection/src/commonTest/kotlin/StaleFieldsTest.kt +++ b/tests/garbage-collection/src/commonTest/kotlin/StaleFieldsTest.kt @@ -10,13 +10,13 @@ import com.apollographql.cache.normalized.api.CacheHeaders import com.apollographql.cache.normalized.api.CacheKey import com.apollographql.cache.normalized.api.GlobalMaxAgeProvider import com.apollographql.cache.normalized.api.SchemaCoordinatesMaxAgeProvider +import com.apollographql.cache.normalized.apolloStore import com.apollographql.cache.normalized.cacheHeaders import com.apollographql.cache.normalized.cacheManager import com.apollographql.cache.normalized.fetchPolicy import com.apollographql.cache.normalized.memory.MemoryCacheFactory import com.apollographql.cache.normalized.removeStaleFields import com.apollographql.cache.normalized.sql.SqlNormalizedCacheFactory -import com.apollographql.cache.normalized.store import com.apollographql.cache.normalized.testing.append import com.apollographql.cache.normalized.testing.fieldKey import com.apollographql.cache.normalized.testing.runTest @@ -66,7 +66,7 @@ class StaleFieldsTest { Cache.maxAges, defaultMaxAge = 120.seconds, ) - var removedFieldsAndRecords = apolloClient.store.removeStaleFields(maxAgeProvider) + var removedFieldsAndRecords = apolloClient.apolloStore.removeStaleFields(maxAgeProvider) // Repository.stars has a max age of 60 seconds, so they should be removed / User has a max age of 90 seconds, so Repository.starGazers should be kept assertEquals( setOf( @@ -88,7 +88,7 @@ class StaleFieldsTest { .fetchPolicy(FetchPolicy.NetworkOnly) .cacheHeaders(receivedDate(currentTimeSeconds() - 90)) .execute() - removedFieldsAndRecords = apolloClient.store.removeStaleFields(maxAgeProvider) + removedFieldsAndRecords = apolloClient.apolloStore.removeStaleFields(maxAgeProvider) // Repository.stars and Repository.starGazers should be removed assertEquals( setOf( @@ -143,7 +143,7 @@ class StaleFieldsTest { Cache.maxAges, defaultMaxAge = 120.seconds, ) - var removedFieldsAndRecords = apolloClient.store.removeStaleFields(maxAgeProvider) + var removedFieldsAndRecords = apolloClient.apolloStore.removeStaleFields(maxAgeProvider) // Project.velocity has a max age of 60 seconds, so they should be removed / Project.isUrgent has a max age of 90 seconds, so they should be kept assertEquals( setOf( @@ -165,7 +165,7 @@ class StaleFieldsTest { .fetchPolicy(FetchPolicy.NetworkOnly) .cacheHeaders(receivedDate(currentTimeSeconds() - 90)) .execute() - removedFieldsAndRecords = apolloClient.store.removeStaleFields(maxAgeProvider) + removedFieldsAndRecords = apolloClient.apolloStore.removeStaleFields(maxAgeProvider) // Project.velocity and Project.isUrgent should be removed, their records being empty they should be removed assertEquals( setOf( @@ -217,7 +217,7 @@ class StaleFieldsTest { assertTrue(allRecords[CacheKey("Repository:1")]!!.fields.containsKey("stars")) assertTrue(allRecords[CacheKey("Repository:1")]!!.fields.containsKey("starGazers")) - var removedFieldsAndRecords = apolloClient.store.removeStaleFields(GlobalMaxAgeProvider(Duration.INFINITE)) + var removedFieldsAndRecords = apolloClient.apolloStore.removeStaleFields(GlobalMaxAgeProvider(Duration.INFINITE)) // Everything is stale assertEquals( setOf( @@ -260,7 +260,8 @@ class StaleFieldsTest { .cacheHeaders(expirationDate(currentTimeSeconds() - 60)) .execute() - removedFieldsAndRecords = apolloClient.store.removeStaleFields(GlobalMaxAgeProvider(Duration.INFINITE), maxStale = 70.seconds) + removedFieldsAndRecords = + apolloClient.apolloStore.removeStaleFields(GlobalMaxAgeProvider(Duration.INFINITE), maxStale = 70.seconds) // Nothing is stale assertEquals( emptySet(), diff --git a/tests/normalization-tests/src/concurrentTest/kotlin/com/example/SqlNormalizationTest.kt b/tests/normalization-tests/src/concurrentTest/kotlin/com/example/SqlNormalizationTest.kt index 22885bfb..72a5d1b6 100644 --- a/tests/normalization-tests/src/concurrentTest/kotlin/com/example/SqlNormalizationTest.kt +++ b/tests/normalization-tests/src/concurrentTest/kotlin/com/example/SqlNormalizationTest.kt @@ -4,10 +4,10 @@ import com.apollographql.apollo.ApolloClient import com.apollographql.cache.normalized.FetchPolicy import com.apollographql.cache.normalized.allRecords import com.apollographql.cache.normalized.api.CacheKey +import com.apollographql.cache.normalized.apolloStore import com.apollographql.cache.normalized.fetchPolicy import com.apollographql.cache.normalized.normalizedCache import com.apollographql.cache.normalized.sql.SqlNormalizedCacheFactory -import com.apollographql.cache.normalized.store import com.apollographql.cache.normalized.testing.append import com.apollographql.cache.normalized.testing.runTest import com.apollographql.mockserver.MockServer @@ -25,7 +25,7 @@ class SqlNormalizationTest { .normalizedCache(SqlNormalizedCacheFactory()) .build() - apolloClient.store.clearAll() + apolloClient.apolloStore.clearAll() mockserver.enqueueString( // language=JSON """ @@ -55,7 +55,7 @@ class SqlNormalizationTest { ) apolloClient.mutation(CreateUserMutation("John")).fetchPolicy(FetchPolicy.NetworkOnly).execute() - apolloClient.store.accessCache { normalizedCache -> + apolloClient.apolloStore.accessCache { normalizedCache -> assertContentEquals( listOf( CacheKey.MUTATION_ROOT, diff --git a/tests/normalized-cache/src/commonTest/kotlin/fragmentnormalizer/FragmentNormalizerTest.kt b/tests/normalized-cache/src/commonTest/kotlin/fragmentnormalizer/FragmentNormalizerTest.kt index 43e21e81..8f8e6ba4 100644 --- a/tests/normalized-cache/src/commonTest/kotlin/fragmentnormalizer/FragmentNormalizerTest.kt +++ b/tests/normalized-cache/src/commonTest/kotlin/fragmentnormalizer/FragmentNormalizerTest.kt @@ -3,10 +3,10 @@ package test.fragmentnormalizer import com.apollographql.apollo.ApolloClient import com.apollographql.cache.normalized.api.CacheKey import com.apollographql.cache.normalized.api.IdCacheKeyGenerator +import com.apollographql.cache.normalized.apolloStore import com.apollographql.cache.normalized.internal.normalized import com.apollographql.cache.normalized.memory.MemoryCacheFactory import com.apollographql.cache.normalized.normalizedCache -import com.apollographql.cache.normalized.store import com.apollographql.cache.normalized.testing.append import com.apollographql.cache.normalized.testing.runTest import fragmentnormalizer.fragment.ConversationFragment @@ -61,19 +61,19 @@ class FragmentNormalizerTest { ), true ) - apolloClient.store.writeFragment( + apolloClient.apolloStore.writeFragment( ConversationFragmentImpl(), CacheKey(fragment1.id), fragment1Read, ) - apolloClient.store.writeFragment( + apolloClient.apolloStore.writeFragment( ConversationFragmentImpl(), CacheKey(fragment2.id), fragment2Read, ) - fragment1 = apolloClient.store.readFragment( + fragment1 = apolloClient.apolloStore.readFragment( ConversationFragmentImpl(), CacheKey(fragment1.id), ).data diff --git a/tests/pagination/src/commonTest/kotlin/EmbedTest.kt b/tests/pagination/src/commonTest/kotlin/EmbedTest.kt index c529a68f..4263092d 100644 --- a/tests/pagination/src/commonTest/kotlin/EmbedTest.kt +++ b/tests/pagination/src/commonTest/kotlin/EmbedTest.kt @@ -4,10 +4,10 @@ import com.apollographql.apollo.ApolloClient import com.apollographql.cache.normalized.api.CacheKey import com.apollographql.cache.normalized.api.CacheKeyGenerator import com.apollographql.cache.normalized.api.CacheKeyGeneratorContext +import com.apollographql.cache.normalized.apolloStore import com.apollographql.cache.normalized.internal.normalized import com.apollographql.cache.normalized.memory.MemoryCacheFactory import com.apollographql.cache.normalized.normalizedCache -import com.apollographql.cache.normalized.store import com.apollographql.cache.normalized.testing.runTest import embed.GetHeroQuery import kotlin.test.Test @@ -47,8 +47,8 @@ class EmbedTest { listOf(GetHeroQuery.Friend("Luke", GetHeroQuery.Pet("Snoopy")), GetHeroQuery.Friend("Leia", GetHeroQuery.Pet("Fluffy"))) ) ) - client.store.writeOperation(query, data) - val dataFromStore = client.store.readOperation(query).data + client.apolloStore.writeOperation(query, data) + val dataFromStore = client.apolloStore.readOperation(query).data assertEquals(data, dataFromStore) } } diff --git a/tests/partial-results/src/commonTest/kotlin/test/CachePartialResultTest.kt b/tests/partial-results/src/commonTest/kotlin/test/CachePartialResultTest.kt index 5cb31ca5..4997ed96 100644 --- a/tests/partial-results/src/commonTest/kotlin/test/CachePartialResultTest.kt +++ b/tests/partial-results/src/commonTest/kotlin/test/CachePartialResultTest.kt @@ -18,13 +18,13 @@ import com.apollographql.cache.normalized.api.IdCacheKeyGenerator import com.apollographql.cache.normalized.api.IdCacheKeyResolver import com.apollographql.cache.normalized.api.Record import com.apollographql.cache.normalized.api.SchemaCoordinatesMaxAgeProvider +import com.apollographql.cache.normalized.apolloStore import com.apollographql.cache.normalized.cacheManager import com.apollographql.cache.normalized.fetchFromCache import com.apollographql.cache.normalized.fetchPolicy import com.apollographql.cache.normalized.fetchPolicyInterceptor import com.apollographql.cache.normalized.memory.MemoryCacheFactory import com.apollographql.cache.normalized.normalizedCache -import com.apollographql.cache.normalized.store import com.apollographql.cache.normalized.storeReceivedDate import com.apollographql.cache.normalized.testing.append import com.apollographql.cache.normalized.testing.assertErrorsEquals @@ -310,7 +310,7 @@ class CachePartialResultTest { ) // Remove project lead from the cache - apolloClient.store.remove(CacheKey("User:3")) + apolloClient.apolloStore.remove(CacheKey("User:3")) val cacheResult = apolloClient.query(MeWithBestFriendQuery()) .fetchPolicyInterceptor(PartialCacheOnlyInterceptor) .execute() @@ -354,7 +354,7 @@ class CachePartialResultTest { ) // Remove best friend from the cache - apolloClient.store.remove(CacheKey("User:2")) + apolloClient.apolloStore.remove(CacheKey("User:2")) val cacheResult2 = apolloClient.query(MeWithBestFriendQuery()) .fetchPolicyInterceptor(PartialCacheOnlyInterceptor) .execute() @@ -395,7 +395,7 @@ class CachePartialResultTest { ) // Remove project user from the cache - apolloClient.store.remove(CacheKey("User:4")) + apolloClient.apolloStore.remove(CacheKey("User:4")) val cacheResult3 = apolloClient.query(MeWithBestFriendQuery()) .fetchPolicyInterceptor(PartialCacheOnlyInterceptor) .execute() @@ -542,7 +542,7 @@ class CachePartialResultTest { ) // Remove the category from the cache - apolloClient.store.accessCache { cache -> + apolloClient.apolloStore.accessCache { cache -> val record = cache.loadRecord(CacheKey("User:1"), CacheHeaders.NONE)!! cache.remove(CacheKey("User:1"), false) cache.merge(Record(record.key, record.fields - "category"), CacheHeaders.NONE, DefaultRecordMerger) @@ -646,7 +646,7 @@ class CachePartialResultTest { ) // Remove lead from the cache - apolloClient.store.remove(CacheKey("User:2")) + apolloClient.apolloStore.remove(CacheKey("User:2")) val cacheMissResult = apolloClient.query(WithFragmentsQuery()) .fetchPolicyInterceptor(PartialCacheOnlyInterceptor) From 7bf5805fc8984795dda2c2fd1031da89c6dda81a Mon Sep 17 00:00:00 2001 From: BoD Date: Fri, 25 Apr 2025 15:44:25 +0200 Subject: [PATCH 07/11] Update migration guide and changelog --- CHANGELOG.md | 3 +- Writerside/topics/migration-guide.md | 37 +++++++++++++++---- .../topics/pagination/pagination-manual.md | 4 +- 3 files changed, 34 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5778c2f8..d27fd3d0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # Next version (unreleased) -PUT_CHANGELOG_HERE +- Rename `ApolloStore` to `CacheManager` and `SimpleApolloStore` to `ApolloStore`. +- Revert the `ApolloClient.apolloStore` deprecation - keeping the original name makes more sense now after the above rename. # Version 0.0.9 _2025-04-09_ diff --git a/Writerside/topics/migration-guide.md b/Writerside/topics/migration-guide.md index c9a55405..191918dc 100644 --- a/Writerside/topics/migration-guide.md +++ b/Writerside/topics/migration-guide.md @@ -38,11 +38,10 @@ import com.apollographql.cache.normalized.* import com.apollographql.apollo.cache.normalized.api.MemoryCacheFactory // With import com.apollographql.cache.normalized.memory.MemoryCacheFactory - - - ``` +In most cases, this will be enough to migrate your project, but there were a few renames and API breaking changes. Read on for more details. + ## Database schema The SQLite cache now uses a different schema. @@ -106,28 +105,52 @@ store.writeOperation(operation, data).also { store.publish(it) } Previously, if you configured custom scalar adapters on your client, you had to pass them to the `ApolloStore` methods. -Now, `ApolloClient.cacheManager` returns a `SimpleApolloStore`, a wrapper around `ApolloStore` which passes the client's `CustomScalarAdapters` automatically. +Now, `ApolloStore` has a reference to the client's `CustomScalarAdapters` so individual methods no longer need an adapters argument. ```kotlin // Before -client.cacheManager.writeOperation( +client.apolloStore.writeOperation( operation = operation, data = data, customScalarAdapters = client.customScalarAdapters ) // After -client.cacheManager.writeOperation( +client.apolloStore.writeOperation( operation = operation, data = data ) ``` +### Providing your own store + +The `ApolloStore` interface has been renamed to `CacheManager`. If you provide your own implementation, change the parent interface to `CacheManager`. +Correspondingly, the `ApolloClient.Builder.store()` extension has been renamed to `ApolloClient.Builder.cacheManager()`. + +```kotlin +// Before +val MyStore = object : ApolloStore { + // ... +} +val apolloClient = ApolloClient.Builder() + // ... + .store(MyStore) + .build() + +// After +val MyStore = object : CacheManager { + // ... +} +val apolloClient = ApolloClient.Builder() + // ... + .cacheManager(MyStore) + .build() +``` + ### Other changes - `readFragment()` now returns a `ReadResult` (it previously returned a ``). This allows for surfacing metadata associated to the returned data, e.g. staleness. - Records are now rooted per operation type (`QUERY_ROOT`, `MUTATION_ROOT`, `SUBSCRIPTION_ROOT`), when previously these were all at the same level, which could cause conflicts. -- `ApolloClient.cacheManager` is deprecated in favor of `ApolloClient.store` for consistency. ## CacheResolver, CacheKeyResolver diff --git a/Writerside/topics/pagination/pagination-manual.md b/Writerside/topics/pagination/pagination-manual.md index 994c4c7e..84e935e1 100644 --- a/Writerside/topics/pagination/pagination-manual.md +++ b/Writerside/topics/pagination/pagination-manual.md @@ -23,8 +23,8 @@ suspend fun fetchAndMergePage(nextPage: Int) { ) // 4. Update the cache with the merged list - val keys = apolloClient.cacheManager.writeOperation(operation = listQuery, operationData = dataWithMergedList) - apolloClient.cacheManager.publish(keys) + val keys = apolloClient.apolloStore.writeOperation(operation = listQuery, operationData = dataWithMergedList) + apolloClient.apolloStore.publish(keys) } ``` From b8527aed36a75ef3ca8fd4c97ca49bb9e0f169ea Mon Sep 17 00:00:00 2001 From: BoD Date: Fri, 25 Apr 2025 15:59:57 +0200 Subject: [PATCH 08/11] Tweak a few docs --- .../topics/pagination/pagination-other.md | 19 +++++++++++-------- .../pagination/pagination-relay-style.md | 15 +++++++++------ 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/Writerside/topics/pagination/pagination-other.md b/Writerside/topics/pagination/pagination-other.md index 1420d703..db217b46 100644 --- a/Writerside/topics/pagination/pagination-other.md +++ b/Writerside/topics/pagination/pagination-other.md @@ -15,7 +15,7 @@ extend type Query @fieldPolicy(forField: "usersPage" paginationArgs: "page") ``` -> This can also be done programmatically by configuring the `ApolloStore` with a [`FieldKeyGenerator`](https://apollographql.github.io/apollo-kotlin-normalized-cache/kdoc/normalized-cache/com.apollographql.cache.normalized.api/-field-key-generator/index.html?query=interface%20FieldKeyGenerator) implementation. +> This can also be done programmatically by configuring your cache with a [`FieldKeyGenerator`](https://apollographql.github.io/apollo-kotlin-normalized-cache/kdoc/normalized-cache/com.apollographql.cache.normalized.api/-field-key-generator/index.html?query=interface%20FieldKeyGenerator) implementation. With that in place, after fetching the first page, the cache will look like this: @@ -44,7 +44,7 @@ This is because the field key is now the same for all pages and the default merg #### Record merging To fix this, we need to supply the store with a piece of code that can merge the lists in a sensible way. -This is done by passing a [`RecordMerger`](https://apollographql.github.io/apollo-kotlin-normalized-cache/kdoc/normalized-cache/com.apollographql.cache.normalized.api/-record-merger/index.html?query=interface%20RecordMerger) to the `ApolloStore` constructor: +This is done by passing a [`RecordMerger`](https://apollographql.github.io/apollo-kotlin-normalized-cache/kdoc/normalized-cache/com.apollographql.cache.normalized.api/-record-merger/index.html?query=interface%20RecordMerger) when configuring your cache: ```kotlin object MyFieldMerger : FieldRecordMerger.FieldMerger { @@ -59,10 +59,13 @@ object MyFieldMerger : FieldRecordMerger.FieldMerger { } } -val cacheManager = ApolloStore( - normalizedCacheFactory = cacheFactory, - recordMerger = FieldRecordMerger(MyFieldMerger), // Configure the store with the custom merger -) +val client = ApolloClient.Builder() + // ... + .normalizedCache( + normalizedCacheFactory = cacheFactory, + recordMerger = FieldRecordMerger(MyFieldMerger), // Configure the store with the custom merger + ) + .build() ``` With this, the cache will be as expected after fetching the second page: @@ -99,7 +102,7 @@ Now let's store in the metadata of each `UserConnection` field the values of the as well as the values of the first and last cursor in its list. This will allow us to insert new pages in the correct position later on. -This is done by passing a [`MetadataGenerator`](https://apollographql.github.io/apollo-kotlin-normalized-cache/kdoc/normalized-cache/com.apollographql.cache.normalized.api/-metadata-generator/index.html?query=interface%20MetadataGenerator) to the `ApolloStore` constructor: +This is done by passing a [`MetadataGenerator`](https://apollographql.github.io/apollo-kotlin-normalized-cache/kdoc/normalized-cache/com.apollographql.cache.normalized.api/-metadata-generator/index.html?query=interface%20MetadataGenerator) when configuring the cache: ```kotlin class ConnectionMetadataGenerator : MetadataGenerator { @@ -144,7 +147,7 @@ extend type Query @typePolicy(embeddedFields: "usersConnection") extend type UserConnection @typePolicy(embeddedFields: "edges") ``` -> This can also be done programmatically by configuring the `ApolloStore` with an [`EmbeddedFieldsProvider`](https://apollographql.github.io/apollo-kotlin-normalized-cache/kdoc/normalized-cache/com.apollographql.cache.normalized.api/-embedded-fields-provider/index.html?query=interface%20EmbeddedFieldsProvider) implementation. +> This can also be done programmatically by configuring the cache with an [`EmbeddedFieldsProvider`](https://apollographql.github.io/apollo-kotlin-normalized-cache/kdoc/normalized-cache/com.apollographql.cache.normalized.api/-embedded-fields-provider/index.html?query=interface%20EmbeddedFieldsProvider) implementation. Now that we have the metadata and embedded fields in place, we can implement the `RecordMerger` (simplified for brevity): diff --git a/Writerside/topics/pagination/pagination-relay-style.md b/Writerside/topics/pagination/pagination-relay-style.md index d287e6fb..c8845ff8 100644 --- a/Writerside/topics/pagination/pagination-relay-style.md +++ b/Writerside/topics/pagination/pagination-relay-style.md @@ -55,14 +55,17 @@ that return a connection: extend type Query @typePolicy(connectionFields: "usersConnection") ``` -In Kotlin, configure the `ApolloStore` like this, using the generated `Pagination` object: +In Kotlin, configure the cache like this, using the generated `Pagination` object: ```kotlin -val cacheManager = ApolloStore( - normalizedCacheFactory = cacheFactory, - metadataGenerator = ConnectionMetadataGenerator(Pagination.connectionTypes), - recordMerger = ConnectionRecordMerger -) +val client = ApolloClient.Builder() + // ... + .normalizedCache( + normalizedCacheFactory = cacheFactory, + metadataGenerator = ConnectionMetadataGenerator(Pagination.connectionTypes), + recordMerger = ConnectionRecordMerger + ) + .build() ``` Query `UsersConnection()` to fetch new pages and update the cache, and watch it to observe the full list. From 3cefbaa104857e63c9609012ad55734a73e45be6 Mon Sep 17 00:00:00 2001 From: BoD Date: Fri, 25 Apr 2025 16:02:13 +0200 Subject: [PATCH 09/11] Fix incorrect rename --- .../apollographql/cache/normalized/api/ApolloCacheHeaders.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/api/ApolloCacheHeaders.kt b/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/api/ApolloCacheHeaders.kt index bf524db0..65c72f16 100644 --- a/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/api/ApolloCacheHeaders.kt +++ b/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/api/ApolloCacheHeaders.kt @@ -14,7 +14,7 @@ object ApolloCacheHeaders { */ const val MEMORY_CACHE_ONLY = "memory-cache-only" - @Deprecated(level = DeprecationLevel.ERROR, message = "This header has no effect and will be removed in a future release. Use CacheManager.remove() instead.") + @Deprecated(level = DeprecationLevel.ERROR, message = "This header has no effect and will be removed in a future release. Use ApolloStore.remove() instead.") const val EVICT_AFTER_READ = "evict-after-read" /** From 73a15d99804182305c4f18f92d506fb3bd88194d Mon Sep 17 00:00:00 2001 From: BoD Date: Fri, 25 Apr 2025 16:10:49 +0200 Subject: [PATCH 10/11] A few renames for consistency --- .../kotlin/com/example/NormalizationTest.kt | 12 ++--- .../kotlin/circular/CircularCacheReadTest.kt | 6 +-- .../declarativecache/DeclarativeCacheTest.kt | 40 +++++++-------- .../kotlin/MemoryCacheOnlyTest.kt | 10 ++-- .../commonTest/kotlin/test/StoreErrorsTest.kt | 50 +++++++++---------- 5 files changed, 59 insertions(+), 59 deletions(-) diff --git a/tests/normalization-tests/src/commonTest/kotlin/com/example/NormalizationTest.kt b/tests/normalization-tests/src/commonTest/kotlin/com/example/NormalizationTest.kt index c3951e9b..b5166c42 100644 --- a/tests/normalization-tests/src/commonTest/kotlin/com/example/NormalizationTest.kt +++ b/tests/normalization-tests/src/commonTest/kotlin/com/example/NormalizationTest.kt @@ -50,7 +50,7 @@ internal object IdBasedCacheKeyResolver : CacheResolver, CacheKeyGenerator { class NormalizationTest { @Test fun issue3672() = runTest { - val store = CacheManager( + val cacheManager = CacheManager( normalizedCacheFactory = MemoryCacheFactory(), cacheKeyGenerator = IdBasedCacheKeyResolver, cacheResolver = IdBasedCacheKeyResolver @@ -61,15 +61,15 @@ class NormalizationTest { val data1 = Buffer().writeUtf8(nestedResponse).jsonReader().toApolloResponse(operation = query, customScalarAdapters = CustomScalarAdapters.Empty) .dataOrThrow() - store.writeOperation(query, data1) + cacheManager.writeOperation(query, data1) - val data2 = store.readOperation(query).data + val data2 = cacheManager.readOperation(query).data assertEquals(data2, data1) } @Test fun issue3672_2() = runTest { - val store = CacheManager( + val cacheManager = CacheManager( normalizedCacheFactory = MemoryCacheFactory(), cacheKeyGenerator = IdBasedCacheKeyResolver, cacheResolver = IdBasedCacheKeyResolver @@ -79,9 +79,9 @@ class NormalizationTest { val data1 = Buffer().writeUtf8(nestedResponse_list).jsonReader() .toApolloResponse(operation = query, customScalarAdapters = CustomScalarAdapters.Empty).dataOrThrow() - store.writeOperation(query, data1) + cacheManager.writeOperation(query, data1) - val data2 = store.readOperation(query).data + val data2 = cacheManager.readOperation(query).data assertEquals(data2, data1) } diff --git a/tests/normalized-cache/src/commonTest/kotlin/circular/CircularCacheReadTest.kt b/tests/normalized-cache/src/commonTest/kotlin/circular/CircularCacheReadTest.kt index 07bb8a00..cb3b3a2a 100644 --- a/tests/normalized-cache/src/commonTest/kotlin/circular/CircularCacheReadTest.kt +++ b/tests/normalized-cache/src/commonTest/kotlin/circular/CircularCacheReadTest.kt @@ -10,7 +10,7 @@ import kotlin.test.assertEquals class CircularCacheReadTest { @Test fun circularReferenceDoesNotStackOverflow() = runTest { - val store = CacheManager(MemoryCacheFactory()) + val cacheManager = CacheManager(MemoryCacheFactory()) val operation = GetUserQuery() @@ -28,8 +28,8 @@ class CircularCacheReadTest { ) ) - store.writeOperation(operation, data) - val result = store.readOperation(operation).data!! + cacheManager.writeOperation(operation, data) + val result = cacheManager.readOperation(operation).data!! assertEquals("42", result.user.friend.id) } } diff --git a/tests/normalized-cache/src/commonTest/kotlin/declarativecache/DeclarativeCacheTest.kt b/tests/normalized-cache/src/commonTest/kotlin/declarativecache/DeclarativeCacheTest.kt index 932d09b1..97fd64f7 100644 --- a/tests/normalized-cache/src/commonTest/kotlin/declarativecache/DeclarativeCacheTest.kt +++ b/tests/normalized-cache/src/commonTest/kotlin/declarativecache/DeclarativeCacheTest.kt @@ -22,54 +22,54 @@ class DeclarativeCacheTest { @Test fun typePolicyIsWorking() = runTest { - val store = CacheManager(MemoryCacheFactory()) + val cacheManager = CacheManager(MemoryCacheFactory()) // Write a book at the "promo" path val promoOperation = GetPromoBookQuery() val promoData = GetPromoBookQuery.Data(GetPromoBookQuery.PromoBook("Promo", "42", "Book")) - store.writeOperation(promoOperation, promoData) + cacheManager.writeOperation(promoOperation, promoData) // Overwrite the book title through the "other" path val otherOperation = GetOtherBookQuery() val otherData = GetOtherBookQuery.Data(GetOtherBookQuery.OtherBook("42", "Other", "Book")) - store.writeOperation(otherOperation, otherData) + cacheManager.writeOperation(otherOperation, otherData) // Get the "promo" book again, the title must be updated - val data = store.readOperation(promoOperation).data!! + val data = cacheManager.readOperation(promoOperation).data!! assertEquals("Other", data.promoBook?.title) } @Test fun fallbackIdIsWorking() = runTest { - val store = CacheManager(MemoryCacheFactory()) + val cacheManager = CacheManager(MemoryCacheFactory()) // Write a library at the "promo" path val promoOperation = GetPromoLibraryQuery() val promoData = GetPromoLibraryQuery.Data(GetPromoLibraryQuery.PromoLibrary("PromoAddress", "3", "Library")) - store.writeOperation(promoOperation, promoData) + cacheManager.writeOperation(promoOperation, promoData) // Overwrite the library address through the "other" path val otherOperation = GetOtherLibraryQuery() val otherData = GetOtherLibraryQuery.Data(GetOtherLibraryQuery.OtherLibrary("3", "OtherAddress", "Library")) - store.writeOperation(otherOperation, otherData) + cacheManager.writeOperation(otherOperation, otherData) // Get the "promo" library again, the address must be updated - val data = store.readOperation(promoOperation).data!! + val data = cacheManager.readOperation(promoOperation).data!! assertEquals("OtherAddress", data.promoLibrary?.address) } @Test fun fieldPolicyIsWorking() = runTest { - val store = CacheManager(MemoryCacheFactory()) + val cacheManager = CacheManager(MemoryCacheFactory()) val bookQuery1 = GetPromoBookQuery() val bookData1 = GetPromoBookQuery.Data(GetPromoBookQuery.PromoBook("Promo", "42", "Book")) - store.writeOperation(bookQuery1, bookData1) + cacheManager.writeOperation(bookQuery1, bookData1) val bookQuery2 = GetBookQuery("42") - val bookData2 = store.readOperation(bookQuery2).data!! + val bookData2 = cacheManager.readOperation(bookQuery2).data!! assertEquals("Promo", bookData2.book?.title) @@ -82,10 +82,10 @@ class DeclarativeCacheTest { ) ) - store.writeOperation(authorQuery1, authorData1) + cacheManager.writeOperation(authorQuery1, authorData1) val authorQuery2 = GetAuthorQuery("Pierre", "Bordage") - val authorData2 = store.readOperation(authorQuery2).data!! + val authorData2 = cacheManager.readOperation(authorQuery2).data!! assertEquals("Pierre", authorData2.author?.firstName) assertEquals("Bordage", authorData2.author?.lastName) @@ -107,22 +107,22 @@ class DeclarativeCacheTest { return FieldPolicyCacheResolver.resolveField(context) } } - val store = CacheManager(MemoryCacheFactory(), cacheResolver = cacheResolver) + val cacheManager = CacheManager(MemoryCacheFactory(), cacheResolver = cacheResolver) val promoOperation = GetPromoBookQuery() - store.writeOperation(promoOperation, GetPromoBookQuery.Data(GetPromoBookQuery.PromoBook("Title1", "1", "Book"))) - store.writeOperation(promoOperation, GetPromoBookQuery.Data(GetPromoBookQuery.PromoBook("Title2", "2", "Book"))) - store.writeOperation(promoOperation, GetPromoBookQuery.Data(GetPromoBookQuery.PromoBook("Title3", "3", "Book"))) - store.writeOperation(promoOperation, GetPromoBookQuery.Data(GetPromoBookQuery.PromoBook("Title4", "4", "Book"))) + cacheManager.writeOperation(promoOperation, GetPromoBookQuery.Data(GetPromoBookQuery.PromoBook("Title1", "1", "Book"))) + cacheManager.writeOperation(promoOperation, GetPromoBookQuery.Data(GetPromoBookQuery.PromoBook("Title2", "2", "Book"))) + cacheManager.writeOperation(promoOperation, GetPromoBookQuery.Data(GetPromoBookQuery.PromoBook("Title3", "3", "Book"))) + cacheManager.writeOperation(promoOperation, GetPromoBookQuery.Data(GetPromoBookQuery.PromoBook("Title4", "4", "Book"))) var operation = GetBooksQuery(listOf("4", "1")) - var data = store.readOperation(operation).data!! + var data = cacheManager.readOperation(operation).data!! assertEquals("Title4", data.books.get(0).title) assertEquals("Title1", data.books.get(1).title) operation = GetBooksQuery(listOf("3")) - data = store.readOperation(operation).data!! + data = cacheManager.readOperation(operation).data!! assertEquals("Title3", data.books.get(0).title) } diff --git a/tests/normalized-cache/src/concurrentTest/kotlin/MemoryCacheOnlyTest.kt b/tests/normalized-cache/src/concurrentTest/kotlin/MemoryCacheOnlyTest.kt index a45e5325..b9b700af 100644 --- a/tests/normalized-cache/src/concurrentTest/kotlin/MemoryCacheOnlyTest.kt +++ b/tests/normalized-cache/src/concurrentTest/kotlin/MemoryCacheOnlyTest.kt @@ -23,21 +23,21 @@ import kotlin.test.assertIs class MemoryCacheOnlyTest { @Test fun memoryCacheOnlyDoesNotStoreInSqlCache() = runTest { - val store = CacheManager(MemoryCacheFactory().chain(SqlNormalizedCacheFactory())).also { it.clearAll() } - val apolloClient = ApolloClient.Builder().networkTransport(QueueTestNetworkTransport()).cacheManager(store).build() + val cacheManager = CacheManager(MemoryCacheFactory().chain(SqlNormalizedCacheFactory())).also { it.clearAll() } + val apolloClient = ApolloClient.Builder().networkTransport(QueueTestNetworkTransport()).cacheManager(cacheManager).build() val query = GetUserQuery() apolloClient.enqueueTestResponse(query, GetUserQuery.Data(GetUserQuery.User("John", "a@a.com"))) apolloClient.query(query).memoryCacheOnly(true).execute() - val dump: Map, Map> = store.dump() + val dump: Map, Map> = cacheManager.dump() assertEquals(2, dump[MemoryCache::class]!!.size) assertEquals(0, dump[SqlNormalizedCache::class]!!.size) } @Test fun memoryCacheOnlyDoesNotReadFromSqlCache() = runTest { - val store = CacheManager(MemoryCacheFactory().chain(SqlNormalizedCacheFactory())).also { it.clearAll() } + val cacheManager = CacheManager(MemoryCacheFactory().chain(SqlNormalizedCacheFactory())).also { it.clearAll() } val query = GetUserQuery() - store.writeOperation(query, GetUserQuery.Data(GetUserQuery.User("John", "a@a.com"))) + cacheManager.writeOperation(query, GetUserQuery.Data(GetUserQuery.User("John", "a@a.com"))) val store2 = CacheManager(MemoryCacheFactory().chain(SqlNormalizedCacheFactory())) val apolloClient = ApolloClient.Builder().serverUrl("unused").cacheManager(store2).build() diff --git a/tests/store-errors/src/commonTest/kotlin/test/StoreErrorsTest.kt b/tests/store-errors/src/commonTest/kotlin/test/StoreErrorsTest.kt index e15addc4..a0bdc406 100644 --- a/tests/store-errors/src/commonTest/kotlin/test/StoreErrorsTest.kt +++ b/tests/store-errors/src/commonTest/kotlin/test/StoreErrorsTest.kt @@ -41,25 +41,25 @@ class StoreErrorsTest { mockServer.close() } - private val memoryStore = CacheManager(MemoryCacheFactory()) + private val memoryCacheManager = CacheManager(MemoryCacheFactory()) - private val sqlStore = CacheManager(SqlNormalizedCacheFactory()).also { it.clearAll() } + private val sqlCacheManager = CacheManager(SqlNormalizedCacheFactory()).also { it.clearAll() } - private val memoryThenSqlStore = CacheManager(MemoryCacheFactory().chain(SqlNormalizedCacheFactory())).also { it.clearAll() } + private val memoryThenSqlCacheManager = CacheManager(MemoryCacheFactory().chain(SqlNormalizedCacheFactory())).also { it.clearAll() } @Test fun simpleMemory() = runTest(before = { setUp() }, after = { tearDown() }) { - simple(memoryStore) + simple(memoryCacheManager) } @Test fun simpleSql() = runTest(before = { setUp() }, after = { tearDown() }) { - simple(sqlStore) + simple(sqlCacheManager) } @Test fun simpleMemoryThenSql() = runTest(before = { setUp() }, after = { tearDown() }) { - simple(memoryThenSqlStore) + simple(memoryThenSqlCacheManager) } private suspend fun simple(cacheManager: CacheManager) { @@ -128,17 +128,17 @@ class StoreErrorsTest { @Test fun listsMemory() = runTest(before = { setUp() }, after = { tearDown() }) { - lists(memoryStore) + lists(memoryCacheManager) } @Test fun listsSql() = runTest(before = { setUp() }, after = { tearDown() }) { - lists(sqlStore) + lists(sqlCacheManager) } @Test fun listsMemoryThenSql() = runTest(before = { setUp() }, after = { tearDown() }) { - lists(memoryThenSqlStore) + lists(memoryThenSqlCacheManager) } private suspend fun lists(cacheManager: CacheManager) { @@ -227,17 +227,17 @@ class StoreErrorsTest { @Test fun compositeMemory() = runTest(before = { setUp() }, after = { tearDown() }) { - composite(memoryStore) + composite(memoryCacheManager) } @Test fun compositeSql() = runTest(before = { setUp() }, after = { tearDown() }) { - composite(sqlStore) + composite(sqlCacheManager) } @Test fun compositeMemoryThenSql() = runTest(before = { setUp() }, after = { tearDown() }) { - composite(memoryThenSqlStore) + composite(memoryThenSqlCacheManager) } private suspend fun composite(cacheManager: CacheManager) { @@ -342,17 +342,17 @@ class StoreErrorsTest { @Test fun aliasesMemory() = runTest(before = { setUp() }, after = { tearDown() }) { - aliases(memoryStore) + aliases(memoryCacheManager) } @Test fun aliasesSql() = runTest(before = { setUp() }, after = { tearDown() }) { - aliases(sqlStore) + aliases(sqlCacheManager) } @Test fun aliasesMemoryThenSql() = runTest(before = { setUp() }, after = { tearDown() }) { - aliases(memoryThenSqlStore) + aliases(memoryThenSqlCacheManager) } private suspend fun aliases(cacheManager: CacheManager) { @@ -420,17 +420,17 @@ class StoreErrorsTest { @Test fun fragmentsAndAliasesMemory() = runTest(before = { setUp() }, after = { tearDown() }) { - fragmentsAndAliases(memoryStore) + fragmentsAndAliases(memoryCacheManager) } @Test fun fragmentsAndAliasesSql() = runTest(before = { setUp() }, after = { tearDown() }) { - fragmentsAndAliases(sqlStore) + fragmentsAndAliases(sqlCacheManager) } @Test fun fragmentsAndAliasesMemoryThenSql() = runTest(before = { setUp() }, after = { tearDown() }) { - fragmentsAndAliases(memoryThenSqlStore) + fragmentsAndAliases(memoryThenSqlCacheManager) } private fun fragmentsAndAliases(cacheManager: CacheManager) = runTest(before = { setUp() }, after = { tearDown() }) { @@ -534,17 +534,17 @@ class StoreErrorsTest { @Test fun errorsReplaceCachedValuesMemory() = runTest(before = { setUp() }, after = { tearDown() }) { - errorsReplaceCachedValues(memoryStore) + errorsReplaceCachedValues(memoryCacheManager) } @Test fun errorsReplaceCachedValuesSql() = runTest(before = { setUp() }, after = { tearDown() }) { - errorsReplaceCachedValues(sqlStore) + errorsReplaceCachedValues(sqlCacheManager) } @Test fun errorsReplaceCachedValuesMemoryThenSql() = runTest(before = { setUp() }, after = { tearDown() }) { - errorsReplaceCachedValues(memoryThenSqlStore) + errorsReplaceCachedValues(memoryThenSqlCacheManager) } private suspend fun errorsReplaceCachedValues(cacheManager: CacheManager) { @@ -704,7 +704,7 @@ class StoreErrorsTest { query, listOf(Error.Builder("'nickName' can't be reached").path(listOf("me", "nickName")).build()), ) - val normalized: Map = memoryStore.normalize( + val normalized: Map = memoryCacheManager.normalize( executable = query, dataWithErrors = dataWithErrors, ) @@ -719,17 +719,17 @@ class StoreErrorsTest { @Test fun writeOperationMemory() = runTest(before = { setUp() }, after = { tearDown() }) { - writeOperation(memoryStore) + writeOperation(memoryCacheManager) } @Test fun writeOperationSql() = runTest(before = { setUp() }, after = { tearDown() }) { - writeOperation(sqlStore) + writeOperation(sqlCacheManager) } @Test fun writeOperationMemoryThenSql() = runTest(before = { setUp() }, after = { tearDown() }) { - writeOperation(memoryThenSqlStore) + writeOperation(memoryThenSqlCacheManager) } private fun writeOperation(cacheManager: CacheManager) { From 23fc3ad92efcc4275fa45c50bd815eaf99b8c430 Mon Sep 17 00:00:00 2001 From: BoD Date: Fri, 25 Apr 2025 16:21:06 +0200 Subject: [PATCH 11/11] Fix incorrect rename --- .../com/apollographql/cache/normalized/ClientCacheExtensions.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/ClientCacheExtensions.kt b/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/ClientCacheExtensions.kt index 2c677baa..ac7a5884 100644 --- a/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/ClientCacheExtensions.kt +++ b/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/ClientCacheExtensions.kt @@ -153,7 +153,7 @@ fun ApolloClient.Builder.cacheManager(cacheManager: CacheManager, writeToCacheAs * * [fetchPolicy] controls how the result is first queried, while [refetchPolicy] will control the subsequent fetches. * - * Note: when manually updating the cache through [CacheManager], [CacheManager.publish] must be called for watchers to be notified. + * Note: when manually updating the cache through [ApolloStore], [ApolloStore.publish] must be called for watchers to be notified. * * @see fetchPolicy * @see refetchPolicy