views:

888

answers:

1

Hi guys

I have just started using OutputCache on some of my controller actions and I am not quite getting the response I would expect.

I have set the cache time to 5 minutes and the Expires header is coming up the same as the Last-Modified header which is the time that the request was made.

This is the header I am currently getting:

Date                    Thu, 16 Jul 2009 06:35:07 GMT
Server                  Microsoft-IIS/6.0
X-Powered-By            ASP.NET
X-AspNet-Version        2.0.50727
X-AspNetMvc-Version     1.0
Content-Encoding        gzip
Cache-Control           public, max-age=300
Expires                 Thu, 16 Jul 2009 06:35:06 GMT
Last-Modified           Thu, 16 Jul 2009 06:35:03 GMT
Vary                    *
Content-Type            text/html; charset=utf-8
Content-Length          575

This is the header I would expect:

Date                    Thu, 16 Jul 2009 06:35:07 GMT
Server                  Microsoft-IIS/6.0
X-Powered-By            ASP.NET
X-AspNet-Version        2.0.50727
X-AspNetMvc-Version     1.0
Content-Encoding        gzip
Cache-Control           public, max-age=300
Expires                 Thu, 16 Jul 2009 06:40:06 GMT
Last-Modified           Thu, 16 Jul 2009 06:35:03 GMT
Vary                    *
Content-Type            text/html; charset=utf-8
Content-Length          575

Any ideas on why it would be doing this?

Cheers Anthony

+4  A: 

max-age takes precedence (from RFC 2616):

We use the term expires_value to denote the value of the Expires header. We use the term max_age_value to denote an appropriate value of the number of seconds carried by the "max-age" directive of the Cache-Control header in a response (see section 14.9.3).

The max-age directive takes priority over Expires, so if max-age is present in a response, the calculation is simply:

  freshness_lifetime = max_age_value

Otherwise, if Expires is present in the response, the calculation is:

  freshness_lifetime = expires_value - date_value

So the client should use the cached version as you expect.

Frank Krueger
Humm does this only apply for HTTP/1.1? Because I am using a proxy that apparently only supports HTTP/1.0. So does this still apply?
vdh_ant
What the proxy supports only makes a different to what the proxy does with the content. What headers are sent depends on the cache location specified in your output cache attribute.
bzlm
The Cache-Control header was introduced in HTTP/1.1 to deal with limitations in the Expires header. The issue is that the Expires header sets a fixed expiry date which can lead to issues if the client and server clocks are not synchronised.When using a browser that supports HTTP/1.1 (pretty much all browsers), the Expires header is ignored in favour of the Cache-Control - max-age header. The only time the Expires header is used is when the request comes from a browser that only supports HTTP/1.0, not HTTP/1.1.
Russell Giddings