How am I able to logg/see whats in the cache? I have problems setting up the normalized cache eventhough I followed the docs.
In the docs they show how things look under the hood and how objects gets saved in the cache, example:
"favoriteBook": {"id": "bk123", "title": "Les guerriers du silence", "author": "ApolloCacheReference{favoriteBook.author}"}
"favoriteBook.author": {"id": "au456", "name": "Pierre Bordage"}
"QUERY_ROOT": {"favoriteBook": "ApolloCacheReference{favoriteBook}"}
This is what I would like to log with my current cache.
Hi!
There is a method to get the contents of the cache as a String that can be logged:
val dump = apolloClient.apolloStore.dump()
val prettyDump: String = NormalizedCache.prettifyDump(dump)
println(prettyDump)
Hope this helps!
@Benoit_Lubek
The cache is empty:
OptimisticCache {}
MemoryCache {}
Here is my ApolloClient:
private val cacheFactory = MemoryCacheFactory(maxSizeBytes = 10 * 1024 * 1024)
fun getApolloClient(): ApolloClient {
return ApolloClient.Builder()
.serverUrl("https://censored/graphql")
.normalizedCache(cacheFactory)
.build()
}
And here is how I call the query:
val apolloList = getApolloClient().query(GetReportsQuery()).fetchPolicy(
FetchPolicy.CacheFirst).execute()
When I now call the code you send me (after the query succeeds and data is displayed) it shows me an empty cache.
Am I missing something?
Just to be sure, are you calling getApolloClient()
several times? You’ll want to keep an re-use the returned value instead.