diff --git a/Writerside/topics/cache-control.md b/Writerside/topics/cache-control.md index c9d3cd96..78527336 100644 --- a/Writerside/topics/cache-control.md +++ b/Writerside/topics/cache-control.md @@ -29,7 +29,8 @@ val apolloClient = ApolloClient.builder() When storing fields, the cache can also store their **received date**. This date can then be compared to the current date when resolving a field to determine if its age is above its **maximum age**. -To store the **received date** of fields, call [`.storeReceivedDate(true)`](https://apollographql.github.io/apollo-kotlin-normalized-cache-incubating/kdoc/normalized-cache-incubating/com.apollographql.cache.normalized/store-receive-date.html?query=fun%20%3CT%3E%20MutableExecutionOptions%3CT%3E.storeReceiveDate(storeReceiveDate:%20Boolean):%20T), and set your client's cache resolver to [`CacheControlCacheResolver`](https://apollographql.github.io/apollo-kotlin-normalized-cache-incubating/kdoc/normalized-cache-incubating/com.apollographql.cache.normalized.api/-cache-control-cache-resolver/index.html): +To store the **received date** of fields, call [`.storeReceivedDate(true)`](https://apollographql.github.io/apollo-kotlin-normalized-cache-incubating/kdoc/normalized-cache-incubating/com.apollographql.cache.normalized/store-receive-date.html?query=fun%20%3CT%3E%20MutableExecutionOptions%3CT%3E.storeReceivedDate(storeReceivedDate:%20Boolean):%20T), and set your client's cache resolver to [ +`CacheControlCacheResolver`](https://apollographql.github.io/apollo-kotlin-normalized-cache-incubating/kdoc/normalized-cache-incubating/com.apollographql.cache.normalized.api/-cache-control-cache-resolver/index.html): ```kotlin val apolloClient = ApolloClient.builder() diff --git a/Writerside/topics/migration-guide.md b/Writerside/topics/migration-guide.md index f9e3272a..cc565679 100644 --- a/Writerside/topics/migration-guide.md +++ b/Writerside/topics/migration-guide.md @@ -31,9 +31,16 @@ Then update your imports: ```kotlin // Replace import com.apollographql.apollo.cache.normalized.* - // With import com.apollographql.cache.normalized.* + +// Replace +import com.apollographql.apollo.cache.normalized.api.MemoryCacheFactory +// With +import com.apollographql.cache.normalized.memory.MemoryCacheFactory + + + ``` ## Database schema diff --git a/design-docs/Expiration.md b/design-docs/Expiration.md index b886d938..7a1eb4b9 100644 --- a/design-docs/Expiration.md +++ b/design-docs/Expiration.md @@ -25,13 +25,13 @@ and instead use the `Record.metadata` map which can store arbitrary data per fie * A cache resolver that raises a cache miss if the field's received date is older than its max age * (configurable via [maxAgeProvider]) or its expiration date has passed. * - * Received dates are stored by calling `storeReceiveDate(true)` on your `ApolloClient`. + * Received dates are stored by calling `storeReceivedDate(true)` on your `ApolloClient`. * * Expiration dates are stored by calling `storeExpirationDate(true)` on your `ApolloClient`. * * A maximum staleness can be configured via the [ApolloCacheHeaders.MAX_STALE] cache header. * - * @see MutableExecutionOptions.storeReceiveDate + * @see MutableExecutionOptions.storeReceivedDate * @see MutableExecutionOptions.storeExpirationDate * @see MutableExecutionOptions.maxStale */ diff --git a/normalized-cache-incubating/api/normalized-cache-incubating.api b/normalized-cache-incubating/api/normalized-cache-incubating.api index 26807113..79a6d313 100644 --- a/normalized-cache-incubating/api/normalized-cache-incubating.api +++ b/normalized-cache-incubating/api/normalized-cache-incubating.api @@ -159,7 +159,7 @@ public final class com/apollographql/cache/normalized/NormalizedCache { 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/Object; - public static final fun storeReceiveDate (Lcom/apollographql/apollo/api/MutableExecutionOptions;Z)Ljava/lang/Object; + public static final fun storeReceivedDate (Lcom/apollographql/apollo/api/MutableExecutionOptions;Z)Ljava/lang/Object; public static final fun watch (Lcom/apollographql/apollo/ApolloCall;)Lkotlinx/coroutines/flow/Flow; public static final fun watch (Lcom/apollographql/apollo/ApolloCall;Lcom/apollographql/apollo/api/Query$Data;)Lkotlinx/coroutines/flow/Flow; public static final fun writeToCacheAsynchronously (Lcom/apollographql/apollo/api/MutableExecutionOptions;Z)Ljava/lang/Object; diff --git a/normalized-cache-incubating/api/normalized-cache-incubating.klib.api b/normalized-cache-incubating/api/normalized-cache-incubating.klib.api index fe931702..6c17314e 100644 --- a/normalized-cache-incubating/api/normalized-cache-incubating.klib.api +++ b/normalized-cache-incubating/api/normalized-cache-incubating.klib.api @@ -577,6 +577,6 @@ 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/refetchPolicyInterceptor(com.apollographql.apollo.interceptor/ApolloInterceptor): #A // com.apollographql.cache.normalized/refetchPolicyInterceptor|refetchPolicyInterceptor@com.apollographql.apollo.api.MutableExecutionOptions<0:0>(com.apollographql.apollo.interceptor.ApolloInterceptor){0§}[0] final fun <#A: kotlin/Any?> (com.apollographql.apollo.api/MutableExecutionOptions<#A>).com.apollographql.cache.normalized/storeExpirationDate(kotlin/Boolean): #A // com.apollographql.cache.normalized/storeExpirationDate|storeExpirationDate@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/storePartialResponses(kotlin/Boolean): #A // 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/storeReceiveDate(kotlin/Boolean): #A // com.apollographql.cache.normalized/storeReceiveDate|storeReceiveDate@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/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){}[0] diff --git a/normalized-cache-incubating/src/commonMain/kotlin/com/apollographql/cache/normalized/ClientCacheExtensions.kt b/normalized-cache-incubating/src/commonMain/kotlin/com/apollographql/cache/normalized/ClientCacheExtensions.kt index b23a6ddc..a7134314 100644 --- a/normalized-cache-incubating/src/commonMain/kotlin/com/apollographql/cache/normalized/ClientCacheExtensions.kt +++ b/normalized-cache-incubating/src/commonMain/kotlin/com/apollographql/cache/normalized/ClientCacheExtensions.kt @@ -264,12 +264,12 @@ fun MutableExecutionOptions.storePartialResponses(storePartialResponses: ) /** - * @param storeReceiveDate Whether to store the receive date in the cache. + * @param storeReceivedDate Whether to store the receive date in the cache. * * Default: false */ -fun MutableExecutionOptions.storeReceiveDate(storeReceiveDate: Boolean) = addExecutionContext( - StoreReceiveDateContext(storeReceiveDate) +fun MutableExecutionOptions.storeReceivedDate(storeReceivedDate: Boolean) = addExecutionContext( + StoreReceivedDateContext(storeReceivedDate) ) /** @@ -390,8 +390,8 @@ internal val ApolloRequest.memoryCacheOnly internal val ApolloRequest.storePartialResponses get() = executionContext[StorePartialResponsesContext]?.value ?: false -internal val ApolloRequest.storeReceiveDate - get() = executionContext[StoreReceiveDateContext]?.value ?: false +internal val ApolloRequest.storeReceivedDate + get() = executionContext[StoreReceivedDateContext]?.value ?: false internal val ApolloRequest.writeToCacheAsynchronously get() = executionContext[WriteToCacheAsynchronouslyContext]?.value ?: false @@ -569,11 +569,11 @@ internal class StorePartialResponsesContext(val value: Boolean) : ExecutionConte companion object Key : ExecutionContext.Key } -internal class StoreReceiveDateContext(val value: Boolean) : ExecutionContext.Element { +internal class StoreReceivedDateContext(val value: Boolean) : ExecutionContext.Element { override val key: ExecutionContext.Key<*> get() = Key - companion object Key : ExecutionContext.Key + companion object Key : ExecutionContext.Key } internal class StoreExpirationDateContext(val value: Boolean) : ExecutionContext.Element { diff --git a/normalized-cache-incubating/src/commonMain/kotlin/com/apollographql/cache/normalized/GarbageCollection.kt b/normalized-cache-incubating/src/commonMain/kotlin/com/apollographql/cache/normalized/GarbageCollection.kt index 20b03727..4cf0acc3 100644 --- a/normalized-cache-incubating/src/commonMain/kotlin/com/apollographql/cache/normalized/GarbageCollection.kt +++ b/normalized-cache-incubating/src/commonMain/kotlin/com/apollographql/cache/normalized/GarbageCollection.kt @@ -70,7 +70,7 @@ fun ApolloStore.removeUnreachableRecords(): Set { * A field is stale if its received date is older than its max age (configurable via [maxAgeProvider]) or if its expiration date has * passed. A maximum staleness can be passed. * - * Received dates are stored by calling `storeReceiveDate(true)` on your `ApolloClient`. + * Received dates are stored by calling `storeReceivedDate(true)` on your `ApolloClient`. * * Expiration dates are stored by calling `storeExpirationDate(true)` on your `ApolloClient`. * diff --git a/normalized-cache-incubating/src/commonMain/kotlin/com/apollographql/cache/normalized/api/CacheResolver.kt b/normalized-cache-incubating/src/commonMain/kotlin/com/apollographql/cache/normalized/api/CacheResolver.kt index da0cfc46..6e81a293 100644 --- a/normalized-cache-incubating/src/commonMain/kotlin/com/apollographql/cache/normalized/api/CacheResolver.kt +++ b/normalized-cache-incubating/src/commonMain/kotlin/com/apollographql/cache/normalized/api/CacheResolver.kt @@ -9,7 +9,7 @@ import com.apollographql.apollo.mpp.currentTimeMillis import com.apollographql.cache.normalized.api.CacheResolver.ResolvedValue import com.apollographql.cache.normalized.maxStale import com.apollographql.cache.normalized.storeExpirationDate -import com.apollographql.cache.normalized.storeReceiveDate +import com.apollographql.cache.normalized.storeReceivedDate import kotlin.jvm.JvmSuppressWildcards import kotlin.time.Duration @@ -142,7 +142,7 @@ object DefaultCacheResolver : CacheResolver { * A cache resolver that raises a cache miss if the field's received date is older than its max age * (configurable via [maxAgeProvider]) or if its expiration date has passed. * - * Received dates are stored by calling `storeReceiveDate(true)` on your `ApolloClient`. + * Received dates are stored by calling `storeReceivedDate(true)` on your `ApolloClient`. * * Expiration dates are stored by calling `storeExpirationDate(true)` on your `ApolloClient`. * @@ -151,7 +151,7 @@ object DefaultCacheResolver : CacheResolver { * @param maxAgeProvider the provider for the max age of fields * @param delegateResolver the resolver to delegate to for non-stale fields, by default [FieldPolicyCacheResolver] * - * @see MutableExecutionOptions.storeReceiveDate + * @see MutableExecutionOptions.storeReceivedDate * @see MutableExecutionOptions.storeExpirationDate * @see MutableExecutionOptions.maxStale */ diff --git a/normalized-cache-incubating/src/commonMain/kotlin/com/apollographql/cache/normalized/internal/ApolloCacheInterceptor.kt b/normalized-cache-incubating/src/commonMain/kotlin/com/apollographql/cache/normalized/internal/ApolloCacheInterceptor.kt index 004d87b5..b1214433 100644 --- a/normalized-cache-incubating/src/commonMain/kotlin/com/apollographql/cache/normalized/internal/ApolloCacheInterceptor.kt +++ b/normalized-cache-incubating/src/commonMain/kotlin/com/apollographql/cache/normalized/internal/ApolloCacheInterceptor.kt @@ -26,7 +26,7 @@ import com.apollographql.cache.normalized.fetchFromCache import com.apollographql.cache.normalized.memoryCacheOnly import com.apollographql.cache.normalized.optimisticData import com.apollographql.cache.normalized.storePartialResponses -import com.apollographql.cache.normalized.storeReceiveDate +import com.apollographql.cache.normalized.storeReceivedDate import com.apollographql.cache.normalized.writeToCacheAsynchronously import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.emitAll @@ -75,8 +75,8 @@ internal class ApolloCacheInterceptor( maybeAsync(request) { val cacheKeys = if (response.data != null) { var cacheHeaders = request.cacheHeaders + response.cacheHeaders - if (request.storeReceiveDate) { - cacheHeaders += nowReceiveDateCacheHeaders() + if (request.storeReceivedDate) { + cacheHeaders += nowReceivedDateCacheHeaders() } if (request.memoryCacheOnly) { cacheHeaders += CacheHeaders.Builder().addHeader(ApolloCacheHeaders.MEMORY_CACHE_ONLY, "true").build() @@ -248,7 +248,7 @@ internal class ApolloCacheInterceptor( } companion object { - private fun nowReceiveDateCacheHeaders(): CacheHeaders { + private fun nowReceivedDateCacheHeaders(): CacheHeaders { return CacheHeaders.Builder().addHeader(ApolloCacheHeaders.RECEIVED_DATE, (currentTimeMillis() / 1000).toString()).build() } } diff --git a/tests/garbage-collection/src/commonTest/kotlin/ReachableCacheKeysTest.kt b/tests/garbage-collection/src/commonTest/kotlin/ReachableCacheKeysTest.kt index 2e0a1a6e..6e1945f1 100644 --- a/tests/garbage-collection/src/commonTest/kotlin/ReachableCacheKeysTest.kt +++ b/tests/garbage-collection/src/commonTest/kotlin/ReachableCacheKeysTest.kt @@ -12,7 +12,7 @@ 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.storeReceiveDate +import com.apollographql.cache.normalized.storeReceivedDate import com.apollographql.mockserver.MockServer import com.apollographql.mockserver.enqueueString import okio.use @@ -30,7 +30,7 @@ class ReachableCacheKeysTest { ApolloClient.Builder() .serverUrl(mockServer.url()) .store(store) - .storeReceiveDate(true) + .storeReceivedDate(true) .build() .use { apolloClient -> val query = MainQuery(userIds = listOf("42", "43")) diff --git a/tests/partial-results/src/commonTest/kotlin/test/CachePartialResultTest.kt b/tests/partial-results/src/commonTest/kotlin/test/CachePartialResultTest.kt index ea9160b7..9832bcd4 100644 --- a/tests/partial-results/src/commonTest/kotlin/test/CachePartialResultTest.kt +++ b/tests/partial-results/src/commonTest/kotlin/test/CachePartialResultTest.kt @@ -27,7 +27,7 @@ import com.apollographql.cache.normalized.memory.MemoryCacheFactory import com.apollographql.cache.normalized.normalizedCache import com.apollographql.cache.normalized.store import com.apollographql.cache.normalized.storePartialResponses -import com.apollographql.cache.normalized.storeReceiveDate +import com.apollographql.cache.normalized.storeReceivedDate import com.apollographql.mockserver.MockServer import com.apollographql.mockserver.enqueueString import kotlinx.coroutines.flow.Flow @@ -697,7 +697,7 @@ class CachePartialResultTest { ApolloClient.Builder() .serverUrl(mockServer.url()) .normalizedCache(MemoryCacheFactory(), cacheResolver = CacheControlCacheResolver(SchemaCoordinatesMaxAgeProvider(Cache.maxAges, Duration.INFINITE))) - .storeReceiveDate(true) + .storeReceivedDate(true) .build() .use { apolloClient -> val networkResult = apolloClient.query(MeWithNickNameQuery()) @@ -765,7 +765,7 @@ class CachePartialResultTest { ApolloClient.Builder() .serverUrl(mockServer.url()) .normalizedCache(MemoryCacheFactory(), cacheResolver = CacheControlCacheResolver(SchemaCoordinatesMaxAgeProvider(Cache.maxAges, Duration.INFINITE))) - .storeReceiveDate(true) + .storeReceivedDate(true) .build() .use { apolloClient -> val networkResult = apolloClient.query(MeWithEmployeeInfoQuery())