0

We can disable caching globally in jQuery by doing:

$.ajaxSetup({ cache: false });

I'm trying to find a similar option in Apollo Client. I've tried Middleware and Cache-Control headers without luck.

Is it possible to disable cache in a similar way (i.e., by appending a timestamp to the query string) as the previous jQuery option does?

Lenin
  • 679
  • 2
  • 10
  • 15

1 Answers1

0

Try to set the fetchPolicy to "no-cache". like this:

const defaultOptions = {
      watchQuery: {
        fetchPolicy: 'no-cache',
        errorPolicy: 'ignore',
      },
      query: {
        fetchPolicy: 'no-cache',
        errorPolicy: 'all',
      },
    }

const client = new ApolloClient({
    link: concat(authMiddleware, httpLink),
    cache: new InMemoryCache(),
    defaultOptions: defaultOptions,

});

Code from this link.

Zhi Lv
  • 18,845
  • 1
  • 19
  • 30
  • I tried this and IE11 still caches the request (Edge, and any other browser, does not cache it as expected). I think we only have two options: 1. Use a query string timestamp 2. Use Cache-Control headers (see stackoverflow.com/q/4303829/2009886). I'm looking for an option to intercept my Apollo queries and inject a timestamp to the query string (or a similar option). – Lenin Nov 09 '18 at 11:30