ASP.NET MVC: OutputCache and http headers

I just started using OutputCache for some of my actions with the controller, and I am not quite getting the answer I would expect.

I set the cache time to 5 minutes and the Expires header will be the same as the Last-Modified header, which is the request time.

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 title 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 this would be done?

Cheers Anthony

+4
source share
1 answer

max-age has an advantage (from RFC 2616 ):

We use the term expires_value to mean the value of the Expires header. We use the term max_age_value to mean the corresponding number of seconds carried by the "maximum age" Cache-Control header directive in the response (see section 14.9.3).

The Maximum Age Directive takes precedence over Expires, so if there is a maximum age in the answer, the calculation is simple:

  freshness_lifetime = max_age_value 

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

  freshness_lifetime = expires_value - date_value 

Therefore, the client should use the cached version as you expect.

+5
source

All Articles