Apollo client's cache is crashing the browser
See original GitHub issueIntended outcome: I have one query which is used by a dozen sub components but always with different variables. Therefore, caching does not make sense as it’s always different. That is why I added to all queries:
fetchPolicy: 'network-only',
The expectation is to not store anything into the cache as those queries are always different.
Actual outcome:
Problem is that the results are cached regardless of the fetchPolicy option, so if I reload my components a few times the cache is getting HUGE, hundreds of rows.
Therefore the first requests are really fast but the more times they are reloader (re mounted), the slower are the components rendering:
It goes up to 20 seconds per component then kills the app.
After a lot of tests I am 100% positive that this “blue delay” (Content loading) is caused by Apollo storing / accessing its cache.
I am seeing all the data being added by running:
console.log(this.$apollo.provider.defaultClient.readQuery({
query:REPORTS_QUERY
}));
So my question is how can I completely deactivate the cache for those queries. Asking Apollo to just look for the network response without interaction with the cache.
How to reproduce the issue:
Just use a query with a different param so it adds a new row in the cache. You can use a timestamp based on new Date()
so it will change on every request. The more requests you will make, the slower you will be able to access the data.
Version
- apollo-client@2.0.3
Let me know if I can provide any more detail.
Issue Analytics
- State:
- Created 6 years ago
- Comments:8 (3 by maintainers)
Top GitHub Comments
@2Fwebd that fetchPolicy bypasses the cache for the initial request, but then stores it in the cache so that it can be read back later.
I have tossed around the idea of
fetchPolicy: 'raw'
which never touches the cache which may work for you in this case.I’d also like to figure out how to make this not crash your app when using the cache. Can you create a reproduction of this so I can improve the cache?
A
no-cache
FetchPolicy
was added in version 2.2.2.Hopefully this helps - thanks!