How to set the S-MaxAge CacheControl value in an ASP.NET app?

3k views Asked by At

I'm trying to set the cachability of an ASP.NET resource. So if I goto /foo/show it will show a View for some resource, and cache this for a few hours (for example). To do this, I'm using the OutputCache attribute which decorates my Action Method. The details of this cache (against this action method) are found in the web.config file.

When I set this Output Cache, it's correctly setting the maxage value, but the s-maxage value is 0. Why is that?

Here's the code:

[Authorize]
[OutputCache(CacheProfile = "SomeController_Show")]
public ActionResult Show(){ ... }

And here's a snippet of the config file:

<add name="SomeController_Show" duration="3600" varyByParam="authkey;format;blah"  />

and a snippet of the response:

Cache-Control:public, max-age=3576, **s-maxage=0**
Content-Length:746
Content-Type:application/json; charset=utf-8
Date:Tue, 10 Aug 2010 00:42:17 GMT
Expires:Tue, 10 Aug 2010 01:41:53 GMT
Last-Modified:Tue, 10 Aug 2010 00:41:53 GMT
Server:Microsoft-IIS/7.0
Vary:*

Notice how the maxage is correctly set but the s-maxage is not?

1

There are 1 answers

0
Pure.Krome On BEST ANSWER

I found the answer, the [AuthorizeAttribute] clears any maxage to zero. This means, no proxies every cache a view result that has Authorization.

I'm guessing proxies cache content via the url .. so if the url doesn't contain any authentication details (which is really shouldn't... :) ) .. then how does it know which two differing requests are for the same person or not?

(I've added this answer instead of deleting, to help other dev's with this issue).

Also, SIMILAR QUESTION: Can someone explain this block of ASP.NET MVC code to me, please?