You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CHANGELOG.md
+4Lines changed: 4 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,10 @@
1
1
# Next version (unreleased)
2
2
3
3
- The computation of cache keys when multiple key fields are used has changed to avoid potential collisions. Note: this can lead to cache misses after upgrading to this version. (#80)
4
+
- Make SQL cache more robust. (#152)
5
+
- Support simple list cases in `FieldPolicyCacheResolver`. (#142)
6
+
- Fragments selecting the key fields are now automatically added for union members and interface possible types by the compiler plugin. (#141)
@@ -128,7 +139,7 @@ The `ApolloStore` interface has been renamed to `CacheManager`. If you provide y
128
139
Correspondingly, the `ApolloClient.Builder.store()` extension has been renamed to `ApolloClient.Builder.cacheManager()`.
129
140
130
141
```kotlin
131
-
//Before
142
+
//Replace
132
143
valMyStore=object:ApolloStore {
133
144
// ...
134
145
}
@@ -137,7 +148,7 @@ val apolloClient = ApolloClient.Builder()
137
148
.store(MyStore)
138
149
.build()
139
150
140
-
//After
151
+
//With
141
152
valMyStore=object:CacheManager {
142
153
// ...
143
154
}
@@ -152,13 +163,13 @@ val apolloClient = ApolloClient.Builder()
152
163
-`readFragment()` now returns a `ReadResult<D>` (it previously returned a `<D>`). This allows for surfacing metadata associated to the returned data, e.g. staleness.
153
164
- 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.
154
165
155
-
## CacheResolver, CacheKeyResolver
166
+
## `CacheResolver`, `CacheKeyResolver`
156
167
157
168
The APIs of `CacheResolver` and `CacheKeyResolver` have been tweaked to be more future-proof. The main change is that the methods now takes a `ResolverContext` instead of
158
169
individual parameters.
159
170
160
171
```kotlin
161
-
//Before
172
+
//Replace
162
173
interfaceCacheResolver {
163
174
funresolveField(
164
175
field:CompiledField,
@@ -168,23 +179,69 @@ interface CacheResolver {
168
179
): Any?
169
180
}
170
181
171
-
//After
182
+
//With
172
183
interfaceCacheResolver {
173
184
funresolveField(context:ResolverContext): Any?
174
185
}
175
186
```
176
187
177
188
`resolveField` can also now return a `ResolvedValue` when metadata should be returned with the resolved value (e.g. staleness).
178
189
179
-
### CacheKey
190
+
### `TypePolicyCacheKeyGenerator`
191
+
192
+
You can now pass the type policies to the `TypePolicyCacheKeyGenerator` constructor, and it is recommended to do so.
193
+
The type policies are generated by the compiler plugin in `yourpackage.cache.Cache.typePolicies`.
194
+
195
+
If your entities ids are unique across the service, you can pass `CacheKey.Scope.SERVICE` to the `TypePolicyCacheKeyGenerator` constructor
196
+
to save space in the cache and improve hit rates in certain cases.
197
+
198
+
```kotlin
199
+
// Replace
200
+
val apolloClient =ApolloClient.Builder()
201
+
// ...
202
+
.normalizedCache(cacheFactory)
203
+
.build()
204
+
205
+
// With
206
+
val apolloClient =ApolloClient.Builder()
207
+
// ...
208
+
.normalizedCache(
209
+
cacheFactory,
210
+
cacheKeyGenerator =TypePolicyCacheKeyGenerator(
211
+
typePolicies =Cache.typePolicies,
212
+
keyScope =CacheKey.Scope.SERVICE// defaults to TYPE
213
+
)
214
+
)
215
+
.build()
216
+
```
217
+
218
+
### `FieldPolicyCacheResolver`
219
+
220
+
-`FieldPolicyCacheResolver` now supports simple list cases. If your field takes a flat list of ids, you no longer need to implement a custom `CacheResolver` for it and can use `@fieldPolicy`.
221
+
- As for `TypePolicyCacheKeyGenerator`, you can pass `CacheKey.Scope.SERVICE` to the constructor if your ids are unique across the service:
222
+
223
+
```kotlin
224
+
val apolloClient =ApolloClient.Builder()
225
+
// ...
226
+
.normalizedCache(
227
+
cacheFactory,
228
+
cacheKeyGenerator =/*...*/,
229
+
cacheResolver =FieldPolicyCacheResolver(
230
+
keyScope =CacheKey.Scope.SERVICE// defaults to TYPE
231
+
)
232
+
)
233
+
.build()
234
+
```
235
+
236
+
## CacheKey
180
237
181
238
For consistency, the `CacheKey` type is now used instead of `String` in more APIs, e.g.:
182
239
183
240
-`ApolloStore.remove()`
184
241
-`Record.key`
185
242
-`NormalizedCache.loadRecord()`
186
243
187
-
###Removed APIs
244
+
## Removed APIs
188
245
189
246
-`ApolloCacheHeaders.EVICT_AFTER_READ` is removed. Manually call `ApolloStore.remove()` when needed instead.
190
247
-`NormalizedCache.remove(pattern: String)` is removed. Please open an issue if you need this feature back.
Copy file name to clipboardExpand all lines: Writerside/topics/welcome.md
+9-8Lines changed: 9 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,15 +1,16 @@
1
1
# Welcome
2
2
3
-
This repository hosts [Apollo Kotlin](https://github.com/apollographql/apollo-kotlin)'s new normalized cache, aiming to replace the main repository version.
3
+
This is [Apollo Kotlin](https://github.com/apollographql/apollo-kotlin)'s Normalized Cache.
4
+
5
+
For an introduction please read the Normalized Cache [documentation](https://www.apollographql.com/docs/kotlin/caching/normalized-cache).
6
+
7
+
Note: the Normalized Cache used to be part of the [Apollo Kotlin main repository](https://github.com/apollographql/apollo-kotlin).
8
+
It is now hosted in a dedicated repository and published at its own cadence and versioning scheme.
4
9
5
10
## Use in your project
6
11
7
-
> This version is not yet stable and is subject to change. It is recommended to experiment with it in
8
-
> non-critical projects/modules, or behind a feature flag.
9
-
>
10
-
> In particular,
11
-
> - there are no guarantees about the format of the cached data, so you should assume that it may be lost when upgrading
12
-
> - performance and size may not be optimal
12
+
> During the alpha phase, the API is still subject to change, although we will try to make changes in non-breaking ways.
13
+
> For now it is recommended to experiment with this library in non-critical projects/modules, or behind a feature flag.
13
14
14
15
{style="warning"}
15
16
@@ -26,4 +27,4 @@ dependencies {
26
27
}
27
28
```
28
29
29
-
If you were using the stable Normalized Cache before, you can update your imports to the new package, `com.apollographql.cache.normalized.*`.
30
+
If you were using the classic Normalized Cache before, please consult the [migration guide](migration-guide.md).
0 commit comments