Anton Kononenko
Anton Kononenko

Reputation: 493

React-Native fetch API aggressive cache

I'm using fetch API for interacting with server in my [email protected] app, but facing with quite aggressive caching.

Call which I proceed can be expressed like:

fetch(route + '&_t=' + Date.now(), {
  headers: {
    'Cache-Control': 'no-cache',
    'Accept': 'application/json, text/plain, */*',
    'Content-Type': 'application/json',
    'Custom-Auth-Header': 'secret-token'
  },
  method: 'POST',
  body: data,
  cache: 'no-store'
})

In IOS simulator response get cached for 15-20 mins, can be cleared via Reset Content and Settings.

In result I just don't want to have any cache for any of my calls (including GET requests).

I tried all options which I know in order to avoid caching, but seems there is something else, any help would be very appreciated!

Upvotes: 11

Views: 2449

Answers (1)

Peter Machowski
Peter Machowski

Reputation: 477

It turned out caching was caused by the server setting the session cookie. iOS/Android handles cookies automatically so it was used with every fetch call.

The solution was to delete all the cookies on logout using the https://github.com/joeferraro/react-native-cookies library.

Upvotes: 5

Related Questions