这是我用于缓存的 apollo 客户端代码
val apolloSqlHelper = ApolloSqlHelper.create(context,"my_app")
val sqlNormalizedCacheFactory = SqlNormalizedCacheFactory(apolloSqlHelper)
val cacheKeyResolver = object: CacheKeyResolver(){
override fun fromFieldRecordSet(
field: ResponseField,
recordSet: MutableMap<String, Any>
): CacheKey {
return if (recordSet["__typename"] == "Repository") {
CacheKey.from(recordSet["id"] as String)
} else {
CacheKey.NO_KEY
}
}
override fun fromFieldArguments(
field: ResponseField,
variables: Operation.Variables
): CacheKey {
return CacheKey.NO_KEY
}
}
ApolloClient.builder().serverUrl(baseUrl)
.normalizedCache(sqlNormalizedCacheFactory,cacheKeyResolver)
.okHttpClient(okHttpClient).build()
我正在做一个查询,之后阿波罗缓存了我的结果,但是当更多数据添加到查询中时,我不明白如何根据结果是否更改来使缓存无效。如果没有结果更改从缓存中获取数据或获取新数据并更新缓存