I use Fetch to fetch data from server like this:
fetch(url, {
method: 'GET',
cache: 'no-cache'
});
It works fine without any caching sometimes, and sometimes it will get the same result(I'm sure data has changed and I've checked that fact using browser).
It seems like React Native is doing caching under the hood, but how can I disable it?
It should be fixed if you set the cache to reload.
Here are some uses of cache.
// Download a resource with cache busting, to bypass the cache
// completely.
fetch("some.json", {cache: "no-store"})
.then(function(response) { /* consume the response */ });
// Download a resource with cache busting, but update the HTTP
// cache with the downloaded resource.
fetch("some.json", {cache: "reload"})
.then(function(response) { /* consume the response */ });
// Download a resource with cache busting when dealing with a
// properly configured server that will send the correct ETag
// and Date headers and properly handle If-Modified-Since and
// If-None-Match request headers, therefore we can rely on the
// validation to guarantee a fresh response.
fetch("some.json", {cache: "no-cache"})
.then(function(response) { /* consume the response */ });
// Download a resource with economics in mind! Prefer a cached
// albeit stale response to conserve as much bandwidth as possible.
fetch("some.json", {cache: "force-cache"})
.then(function(response) { /* consume the response */ });
Note: Let me know if it doesn't work please and I will update my answer.
There is more about fetch on: hacks.mozilla and developer.mozilla
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With