当前位置 : 主页 > 网络编程 > ASP >

asp.net-mvc – 如何使用OutputCacheProfiles来压缩标头Vary:*

来源:互联网 收集:自由互联 发布时间:2021-06-24
使用下面给出的任何OutputCacheProfiles caching outputCacheSettings outputCacheProfiles clear/ add name="CachingProfileParamEmpty" duration="87" varyByParam="" location="Any" / add name="CachingProfileParamNone" duration="87" varyByP
使用下面给出的任何OutputCacheProfiles

<caching>
  <outputCacheSettings>
    <outputCacheProfiles>
      <clear/>

      <add
        name="CachingProfileParamEmpty"
        duration="87"
        varyByParam=""
        location="Any"
      />

      <add
        name="CachingProfileParamNone"
        duration="87"
        varyByParam="None"
        location="Any"
      />

      <add
        name="CachingProfileParamStar"
        duration="87"
        varyByParam="*"
        location="Any"
      />
    </outputCacheProfiles>
  </outputCacheSettings>
</caching>

标题变化:*始终发送

HTTP/1.1 200 OK
Server: ASP.NET Development Server/10.0.0.0
Date: Mon, 05 Mar 2012 20:11:52 GMT
X-AspNetMvc-Version: 3.0
Cache-Control: public, max-age=87
Expires: Mon, 05 Mar 2012 20:13:13 GMT
Last-Modified: Mon, 05 Mar 2012 20:11:46 GMT
Vary: *
Content-Type: text/html; charset=utf-8
Content-Length: 5368
Connection: Close

这反过来导致浏览器将请求发送到服务器而不是本地缓存.即使使用

this.Response.Cache.SetOmitVaryStar(false);

没有帮助.我可以强制不发送标头的唯一方法是使用直接属性

[OutputCache(Duration = 60, VaryByParam = "", Location = OutputCacheLocation.Any)]
public ActionResult Index()

我究竟做错了什么?我更喜欢使用CacheProfiles,因为可以在web.config中修改它们.

这里发布的标题来自Cassini(服务器:ASP.NET开发服务器/ 10.0.0.0),但我在Windows 2008上的IIS 7中也看到了相同的结果.

对于amit_g可能有点迟,但对于寻找答案的其他人,您可以在配置中指定应用程序范围的输出缓存设置以删除Vary.*响应标头.

<caching>
  <outputCache omitVaryStar="true" />
  <outputCacheSettings>
    <outputCacheProfiles>
       ...
    </outputCacheProfiles>
  </outputCacheSettings>
</caching>
网友评论