Ant*_*nko 11 caching ios react-native
我正在使用fetch API在我的react-native@0.28应用程序中与服务器交互,但面对相当激进的缓存.
我继续的电话可以表达如下:
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'
})
Run Code Online (Sandbox Code Playgroud)
在IOS模拟器中,响应缓存15-20分钟,可以通过重置内容和设置清除.
结果我只是不想为我的任何调用(包括GET请求)提供任何缓存.
我尝试了所有我知道的选项以避免缓存,但似乎还有别的东西,任何帮助都会非常感激!
原来,缓存是由服务器设置会话Cookie引起的。iOS / Android自动处理Cookie,因此每次提取调用都会使用它。
解决方案是使用https://github.com/joeferraro/react-native-cookies库在注销时删除所有cookie 。