Disabling cache in Apollo client when 'cache-control' response header is set with 'no-store'

Actually we are trying to add ‘cache-control’ response header from Apollo Server, but we would like to know how does Apollo Client behave when ‘cache-control’ is present in the response headers.

My question is, will Apollo Client automatically disable the cache when this header(cache-control) is present in the response headers with a value of ‘no-store’, or do I need to set up some configuration in the Apollo Client side for not allowing the cache when cache-control is equal to ‘no-store’?

The Apollo Client cache does not have a TTL cache currently so it does not support reading the Cache-Control headers as they commonly are returned with cache-control max-age=60 to set a specific time.

If you would like to disable the cache for a particular operation you can set the fetch policy in Apollo Client: fetchPolicy: 'no-cache'

Thank @shanemyrick . We have tried with latest apollo/client (v3.9.7) which has a lot of memory improvements as @lenz Apollo Client 3.9 Feature Spotlight – The memory story | Apollo GraphQL Blog

We are using Apollo Client Devtools v4.8.1 to check what data is cached. We would like to confirm that only the “Cache” tab contains cache data. As we can see there is a section within “Queries” about cache data. Please see screenshot attached.

We have created a very basic minimal repository for you to help us confirm the configuration to totally opt-out on queries, mutations, subscriptions is the expected configuration. https://codesandbox.io/p/devbox/m4slm8?file=%2Fsrc%2Fgraphql%2FcreateApolloClient.ts%3A39%2C50-40%2C20&migrateFrom=7yx4hq

Thank you for your time and great project contribution.

That config block matches the expected structure: https://www.apollographql.com/docs/react/api/core/ApolloClient#example-defaultoptions-object

Thank you @shanemyrick for confirming.

I understood that Apollo Chrome extension says “Cache Data” under queries but it is not really cached data. Do you think would be a good idea to rename it to something else?

One last question about caching subscription, as there is no way to say on the default options object, just to confirm that we need to include ‘fetchPolicy: “no-cache”’ in all subscription.

Thank you in advance.

I am not on the client team, so if there is specific bug or issue you would like to raise, that can be done on our GitHub repo.

Does this issue reflect something that you are having issues with? If so feel free to add your comments there: subscribeToMore not rerendering component when watchQuery's fetchPolicy is set to no-cache · Issue #8013 · apollographql/apollo-client · GitHub

Hey @Cr4DLe :wave:

The cache tab in the devtools should only contain cached data. I’ve confirmed this includes the Queries tab as well.

Weird that you’re seeing something in the devtools. If I open your reproduction in its own tab, the devtools show that the query was made, but there is no cache data as expected. See my screenshots.


If you’re not seeing this, could you open an issue in the devtools repo so we can take a closer look?