Safari缓存GET请求(即使禁用了缓存) [英] Safari Caching GET request even with disabled cache
问题描述
我已经设置了我知道的所有标头,以在服务器上禁用缓存(甚至禁用ETAG),但是Safari仍然偶尔(约50%次)缓存我的请求.
I have set all headers that I know of to disable caching (even disabling ETAG) on my server, yet Safari still occasionally (about 50% times) caches my requests.
我正在实现oauth 1,所以:
I am implementing oauth 1, so:
-
浏览器发出
GET /api/user
请求
服务器返回405
浏览器重定向到第三方网站进行身份验证
Browser redirects to 3rd party website to authenticate
浏览器重定向到api/callback
,它将一些信息存储到cookie中.
Browser is redirected to api/callback
which stores some info into cookie.
浏览器被重定向回原始路由.
Browser is redirected back to original route.
浏览器发出GET /api/user
请求,该请求应该成功,但是它会从磁盘缓存中获取405服务.
Browser makes GET /api/user
request which should be successful, however it gets 405 served from disk cache instead.
来自Safari网络检查器的请求摘要
摘要
URL: http://localhost:3000/api/user
状态: 405 Method Not Allowed
来源: Disk Cache
没有请求,由磁盘缓存提供.
No request, served from the disk cache.
传输编码: Identity
内容类型: application/json; charset=utf-8
编译指示: no-cache
缓存控制: private, no-cache, no-store, must-revalidate, max-age=0
不同: Cookie, Accept-Encoding
日期: Wed, 23 Jan 2019 11:34:23 GMT
内容编码: gzip
有效期: Thu, 01 Dec 1994 16:00:00 GMT
连接: close
x-powered by: Express
我不知道怎么了,我将不胜感激.我的
Safari版本为12.0.2
.我无法使用Chrome复制此问题.
I have no idea what's wrong and I will greatly appreciate any help. My
Safari version is 12.0.2
. I wasn't able to replicate this issue with Chrome.
推荐答案
使用Vary: *
.这神奇地解决了我的问题.
Use Vary: *
. This magically solved my problem.
此答案对我有帮助: https://stackoverflow.com/a/2068353/1364158
或者,您可以通过在网址中包含一些无意义的随机查询arg来强制浏览器加载新版本的请求,例如/api/user?ts=18284
Alternatively, you can really force browser to load a new version of request by including some meaningless random query arg in your url, e.g. /api/user?ts=18284
这篇关于Safari缓存GET请求(即使禁用了缓存)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!