反应天然 - 为什么取出卡奇会导致

  • 本文关键字: react-native fetch
  • 更新时间 :
  • 英文 :


我使用fetch从服务器获取数据:

fetch(url, {
    method: 'GET',
    cache: 'no-cache'
});

有时它可以正常工作而无需任何缓存,有时会得到相同的结果(我确定数据已更改,并且我已经使用浏览器检查了该事实)。

似乎React Native在引擎盖下进行缓存,但是我该如何禁用它?

如果将缓存设置为reload,则应修复它。

这是缓存的一些用途。

  // 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 */ });

注意:让我知道它是否不起作用,我将更新答案。

关于fetch的更多信息:hacks.mozilla and developer.mozilla

相关内容

  • 没有找到相关文章

最新更新