ASP.NET MVC and HTTP/1.1 Caching

Overview

HTTP Cache Control Mechanisms

HTTP headers exert influence over what HTTP caches store and for how long.

Cache Related Headers.

There are at least two deprecated headers. These are still useful when we want to support HTTP/1.0 or older browser versions. Other cache related headers are useful for calculating expiration.

Table: Cache Related HTTP headers and corresponding ASP.NET MVC OutputCacheAttribute property values.

Cache Related HTTP Header Corresponding ASP.NET MVC OutputCacheAttribute Property Values
Expires
Pragma: no-cache

Common Cache-Control Header Directives.

The Cache-Control header can have many directive values. The directives work for HTTP/1.1 cache-capable devices and are part of the ASP.NET MVC OutputCacheAttribute.

Table: HTTP Cache-Control directives and corresponding ASP.NET MVC OutputCacheAttribute properties

HTTP Cache-Control Directive Corresponding ASP.NET MVC OutputCacheAttribute Property Values
max-age Duration = Milliseconds
no-store NoStore = true
private Location = OutputCacheLocation.Client | OutputCacheLocation.ServerAndClient
public Location = OutputCacheLocation.Any | OutputCacheLocation.Downstream
no-cache Location = OutputCacheLocation.None | OutputCacheLocation.Server
must-revalidate ?

ASP.NET MVC Default for Location = .

The default is Location = OutputCacheLocation.Any, which should NOT cache personal information such as username, because it goes into a public cache location.

Where to Set Cache-Control?

OutputCache Attribute.

OutputCache Properties.

  <system.web>
    <caching>
      <outputCacheSettings>
        <outputCacheProfiles>
          <add
            name="TransparentClient"
            duration="0"
            location="Client"
            noStore="true" />
        </outputCacheProfiles>
      </outputCacheSettings>
    </caching>
  </system.web>

Research Questions

References