question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Apollo client's cache is crashing the browser

See original GitHub issue

Intended 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:

33696182-f4936dea-dace-11e7-862b-b3839adafc5d

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:closed
  • Created 6 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

8reactions
jbaxleyiiicommented, Dec 8, 2017

@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?

1reaction
hwillsoncommented, May 13, 2018

A no-cache FetchPolicy was added in version 2.2.2.

no-cache: return result from network, fail if network call doesn’t succeed, don’t save to cache

Hopefully this helps - thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Advanced topics on caching in Apollo Client
Advanced topics on caching in Apollo Client. This article describes special cases and considerations when using the Apollo Client cache. Bypassing the cache....
Read more >
Error handling - Apollo GraphQL Docs
A client sent the hash of a query string to execute via automatic persisted queries, but the query was not in the APQ...
Read more >
Handling operation errors - Apollo GraphQL Docs
Apollo Client can encounter a variety of errors when executing operations on your ... graphQLErrors is not populated), and any returned data is...
Read more >
Caching in Apollo Client - Apollo GraphQL Docs
Apollo Client stores the results of your GraphQL queries in a local, normalized, in-memory cache. This enables Apollo Client to respond almost immediately ......
Read more >
@apollo/client | Yarn - Package Manager
watch memory leak. ... Consider cache.reset a destructive method, like cache.evict and cache.modify . ... Avoid refetching observerless queries with ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found