How to supress header Vary:* when using OutputCacheProfiles
Asked Answered
D

2

4

Using any of the OutputCacheProfiles given below

<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>

header Vary:* is always sent

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

which in turn causes the browser to send the request to the server and not cache locally. Even using

this.Response.Cache.SetOmitVaryStar(false);

doesn't help. The only way I can force the header not to be sent is to use direct attribute

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

What am I doing wrong? I would prefer to use the CacheProfiles as those can be modified in the web.config.

The headers posted here are from the Cassini (Server: ASP.NET Development Server/10.0.0.0) but I have seen identical results in IIS 7 on Windows 2008 as well.

Digraph answered 5/3, 2012 at 20:28 Comment(0)
S
10

It may be a bit late for amit_g, but for anyone else looking for an answer, you can specify an application-wide output cache setting in the config to remove the Vary.* response header.

<caching>
  <outputCache omitVaryStar="true" />
  <outputCacheSettings>
    <outputCacheProfiles>
       ...
    </outputCacheProfiles>
  </outputCacheSettings>
</caching>
Selle answered 22/11, 2012 at 9:40 Comment(1)
why does MVC do this...Volunteer
R
3

Note that using "true" for SetOmitVaryStar is the correct value to omit the Vary: * header (not false, which won't omit it).

Using the following code worked for me:

this.Response.Cache.SetOmitVaryStar(true);

Robbinrobbins answered 2/2, 2015 at 23:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.