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?

1 Answer 1

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.

1
  • 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 9, 2018 at 11:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.