Skip to content

Rename 'receiveDate' -> 'receivedDate' #98

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Writerside/topics/cache-control.md
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
9 changes: 8 additions & 1 deletion Writerside/topics/migration-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions design-docs/Expiration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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§<kotlin.Any?>}[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§<kotlin.Any?>}[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§<kotlin.Any?>}[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§<kotlin.Any?>}[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§<kotlin.Any?>}[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§<kotlin.Any?>}[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]
Original file line number Diff line number Diff line change
Expand Up @@ -264,12 +264,12 @@ fun <T> MutableExecutionOptions<T>.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 <T> MutableExecutionOptions<T>.storeReceiveDate(storeReceiveDate: Boolean) = addExecutionContext(
StoreReceiveDateContext(storeReceiveDate)
fun <T> MutableExecutionOptions<T>.storeReceivedDate(storeReceivedDate: Boolean) = addExecutionContext(
StoreReceivedDateContext(storeReceivedDate)
)

/**
Expand Down Expand Up @@ -390,8 +390,8 @@ internal val <D : Operation.Data> ApolloRequest<D>.memoryCacheOnly
internal val <D : Operation.Data> ApolloRequest<D>.storePartialResponses
get() = executionContext[StorePartialResponsesContext]?.value ?: false

internal val <D : Operation.Data> ApolloRequest<D>.storeReceiveDate
get() = executionContext[StoreReceiveDateContext]?.value ?: false
internal val <D : Operation.Data> ApolloRequest<D>.storeReceivedDate
get() = executionContext[StoreReceivedDateContext]?.value ?: false

internal val <D : Operation.Data> ApolloRequest<D>.writeToCacheAsynchronously
get() = executionContext[WriteToCacheAsynchronouslyContext]?.value ?: false
Expand Down Expand Up @@ -569,11 +569,11 @@ internal class StorePartialResponsesContext(val value: Boolean) : ExecutionConte
companion object Key : ExecutionContext.Key<StorePartialResponsesContext>
}

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<StoreReceiveDateContext>
companion object Key : ExecutionContext.Key<StoreReceivedDateContext>
}

internal class StoreExpirationDateContext(val value: Boolean) : ExecutionContext.Element {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ fun ApolloStore.removeUnreachableRecords(): Set<CacheKey> {
* 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`.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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`.
*
Expand All @@ -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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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())
Expand Down