React Native - Fetch call cached
You can set a Header
to prevent the request from being cached.Example below:
return fetch(url, { headers: { 'Cache-Control': 'no-cache' }}).then(function (res) { return res.json();}).catch(function(error) { console.warn('Request Failed: ', error);});
Manosim's answer didn't work for me, but put me on the path to a solution that did work:
fetch(url, { headers: { 'Cache-Control': 'no-cache, no-store, must-revalidate', 'Pragma': 'no-cache', 'Expires': 0 }})
This nailed it.
I had a similar problem with react native (Android) and fetch using clojurescript (instead of js).Adding :cache "no-store" (not in the header) stopped the behavior (caching fetch data on Android App).
I think the code in js should be something like:
fetch(url, {'cache':'no-store'})