即使在传递了缓存控制和编译指示标头之后,Edge仍从缓存提供API

时间:2019-03-11 09:30:19

标签: vue.js axios microsoft-edge asp.net-core-webapi cache-control

API正在从缓存中获取。这仅在Edge中发生。我在stackoverflow中经历了许多类似的问题,但徒劳地尝试了一切。

我在Vue js中添加了与缓存相关的标头

axios.defaults.headers.common['Cache-Control'] = 'private, no-cache, no-store, must-revalidate'
axios.defaults.headers.common['Expires'] = 0
axios.defaults.headers.common['Pragma'] = 'no-cache'
axios.defaults.headers.common['If-Modified-Since'] = 'Mon, 26 Jul 1997 05:00:00 GMT'

我还从服务器端添加了缓存头。

[ResponseCache(NoStore = true, Location = ResponseCacheLocation.None)]
[ServiceFilter(typeof(AuthenticateFilter))]
[Produces("application/json")]
[Route("{tenant}")]
public class DashboardController : Controller
{
} 

“我的请求”标题看起来像是chrome

Accept: application/json, text/plain, */*
Authorization: Token ggggggggggggggggggggg
Cache-Control: private, no-cache, no-store, must-revalidate
Expires: 0
If-Modified-Since: Mon, 26 Jul 1997 05:00:00 GMT
Origin: http://somedummy.com
Pragma: no-cache
Referer: http://somedummy.com/dashboard/sample
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36
withCredentials: true

和响应头:

Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: http://somedummy.com
Cache-Control: no-store,no-cache
Content-Type: application/json; charset=utf-8
Date: Mon, 11 Mar 2019 08:35:36 GMT
Pragma: no-cache
Strict-Transport-Security: max-age=31536000; includeSubDomains;
Transfer-Encoding: chunked
Vary: Origin
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-Powered-By: ASP.NET
X-StackifyID: V1|b6841c38-3ec0-4a46-ac24-699ac8a5af0d|
X-XSS-Protection: 1; mode=block

在IE,chrome和safari中从服务器获取API,但仅在Edge中,即使在开发人员选项中选择了“始终从服务器刷新”选项,也只能从缓存中获取API。

enter image description here

我还在index.html中添加了元

<meta http-equiv="expires" content="-1">
<meta http-equiv="cache-control" content="max-age=0">
<meta http-equiv="cache-control" content="no-cache, no-store, must-revalidate">
<meta http-equiv="pragma" content="no-cache">

控制台中没有错误。没有从Edge进行的飞行前(OPTIONS)呼叫。奇怪的是,打开提琴手然后从Edge中的服务器提供API。

谢谢。

1 个答案:

答案 0 :(得分:1)

您的修改是服务器响应,此操作无效,相反,您应该使用headers: { Pragma: 'no-cache' }

示例:

const api = axios.create({
  headers: { Pragma: 'no-cache' },
});

或将其添加到配置中

const config = {
    headers: { Pragma: 'no-cache'},
    params: { id: this.state.taskID }
}
axios.get("some URL", config).then(...)