简体   繁体   English

React-Native fetch API积极缓存

[英]React-Native fetch API aggressive cache

I'm using fetch API for interacting with server in my react-native@0.28 app, but facing with quite aggressive caching. 我正在使用fetch API在我的react-native@0.28应用程序中与服务器交互,但面对相当激进的缓存。

Call which I proceed can be expressed like: 我继续的电话可以表达如下:

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'
})

In IOS simulator response get cached for 15-20 mins, can be cleared via Reset Content and Settings. 在IOS模拟器中,响应缓存15-20分钟,可以通过重置内容和设置清除。

In result I just don't want to have any cache for any of my calls (including GET requests). 结果我只是不想为我的任何调用(包括GET请求)提供任何缓存。

I tried all options which I know in order to avoid caching, but seems there is something else, any help would be very appreciated! 我尝试了所有我知道的选项以避免缓存,但似乎还有别的东西,任何帮助都会非常感激!

It turned out caching was caused by the server setting the session cookie. 事实证明,缓存是由服务器设置会话cookie引起的。 iOS/Android handles cookies automatically so it was used with every fetch call. iOS / Android自动处理cookie,因此它与每次提取调用一起使用。

The solution was to delete all the cookies on logout using the https://github.com/joeferraro/react-native-cookies library. 解决方案是使用https://github.com/joeferraro/react-native-cookies库删除注销时的所有cookie。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM