If I haven’t configured a <httpCache> in my Apollo...
# apollo-kotlin
s
If I haven’t configured a httpCache in my ApolloClient, does that mean that any calls to httpFetchPolicy on any of my `ApolloCall`s have no effect? I just realized we haven’t got that setup at all, so I am trying to understand how all these calls have been hehaving. Usually we paired them with editing the Apollo cache policy at the same time as well, so I guess we’ve only been relying on the apollo cache so far but we didn’t know it 😅. Which also bring the next question. How does it work if you’ve got both of them configured at the same time? Would most normal cases only need the apollo cache? Basically I am in unfamiliar grounds with this topic and I haven’t found anything in the docs regarding how to make the decision of what we should use, so any help would be appreciated!
b
If I haven’t configured a httpCache in my ApolloClient, does that mean that any calls to httpFetchPolicy on any of my `ApolloCall`s have no effect?
Correct
How does it work if you’ve got both of them configured at the same time?
Well, the HTTP one is last in the call chain. In theory a cache miss at the normalized level could still result in a cache hit at the HTTP level, but I don't expect this scenario to happen often. This page explains the differences between the 2. In summary, the HTTP one is simpler to setup/use but less powerful than the Normalized one.
(sorry meant to say last in the chain, not first)
s
Correct
Damn it must’ve been like that for years 😂 Thanks a lot for helping out! But alright I think it makes sense actually. We got the normalized cache configured already, so adding the Http one is probably like a “why not” situation right? Then I wonder, are there any use cases where you’d want to configure a different fetch policy for one and a different for the other? If not, maybe I could introduce a function locally that just configures the same policy for both caches
g
so adding the Http one is probably like a “why not”
Is it not risky to have normalized + http cache? I've lost enough time with cache issues to consider them very carefully and only pick the more relevant one when possible. Is there advantages to use both of them?
🤔 1
b
hmm well it's true that if you have a different policy (say, cache first on one, and network first on the other), your code may become very confusing
👍 1
s
And speaking of caches, that means then that if one is using both of them, in order to do a full clear to start from a clean slate they’d have to do both right?
Copy code
apolloClient.httpCache.clearAll()
apolloClient.apolloStore.clearAll()
I don’t think either of these functions are referenced inside the documentation. Did a text search in the folder “apollo-kotlin/docs/source”. Should they be mentioned somewhere?
b
they’d have to do both right?
correct
Should they be mentioned somewhere?
Aren't, but probably should yes 😅
g
Sorry to hijack this conversation, but what's the interest of httpCache if the normalized cache store all the structured data?
b
No worries! Do you mean is it useful on its own rather that using the normalized cache, or do you mean is it useful to use both at the same time? Also one difference that's not well documented is that the http and the memory normalized cache have an expiration mechanism, which the SQL normalized cache does't have (yet! it's a work in progress)
g
I mean: is it useful to use both at the same time?
b
Gotcha. Yeah I'm not 100% convinced it would be useful, as you said the normalized cache should already do the job.
🙏 1