Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/410.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript React本机提取缓存不工作(无法启用缓存)_Javascript_React Native_Caching_Http Headers_Fetch - Fatal编程技术网

Javascript React本机提取缓存不工作(无法启用缓存)

Javascript React本机提取缓存不工作(无法启用缓存),javascript,react-native,caching,http-headers,fetch,Javascript,React Native,Caching,Http Headers,Fetch,关于如何在React Native fetch中禁用缓存,有很多问题。我似乎遇到了相反的问题——我有一个服务器端API,它有正确的缓存头(在Google Chrome中,缓存对于fetch调用工作正常) 响应标题在Chrome inspector中可见: Access-Control-Allow-Credentials: true Access-Control-Allow-Origin: * Cache-Control: max-age=172800 Connection: Keep-Alive

关于如何在React Native fetch中禁用缓存,有很多问题。我似乎遇到了相反的问题——我有一个服务器端API,它有正确的缓存头(在Google Chrome中,缓存对于fetch调用工作正常)

响应标题在Chrome inspector中可见:

Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: *
Cache-Control: max-age=172800
Connection: Keep-Alive
Content-Length: 2748
Content-Type: application/json
Date: Thu, 06 Dec 2018 08:55:55 GMT
Expires: Sat, 08 Dec 2018 08:55:55 GMT
Keep-Alive: timeout=5, max=998
Pragma: cache
Server: Apache/2.4.29 (Ubuntu)
服务器上的代码(PHP):

但是,在我的react本机应用程序中,API调用从不缓存。我在某个地方读到缓存不能保证,但我希望缓存在大多数情况下都能工作(设备有足够的内存,如果这可以控制缓存清除的话)。我还在一个模拟器上进行了尝试,并看到总是对服务器进行调用(从不缓存)


这可能是因为它是一个开发构建吗?是否在emulator上禁用缓存?我找不到任何有关此的文档。

您尝试过axios吗?@HelmerBarcos No.希望避免额外的软件包
Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: *
Cache-Control: max-age=172800
Connection: Keep-Alive
Content-Length: 2748
Content-Type: application/json
Date: Thu, 06 Dec 2018 08:55:55 GMT
Expires: Sat, 08 Dec 2018 08:55:55 GMT
Keep-Alive: timeout=5, max=998
Pragma: cache
Server: Apache/2.4.29 (Ubuntu)
$expires = gmdate("D, d M Y H:i:s", time() + AppConfig::mobileApiCacheTimeInSeconds) . " GMT";
header("Expires: $expires");
header("Pragma: cache");
header("Cache-Control: max-age=" . AppConfig::mobileApiCacheTimeInSeconds);