Posts

Showing posts from September, 2012

HTTP Caching, POST, and Vary Headers

Um, yeah, so this should be obvious but was a "derp" moment for me.

When you're generating content from a web service, you can specify a Cache-Control: public to indicate "this can be cached on the client, on the server, and by proxies", and Vary header to indicate that different client headers (e.g. Accept) should yield different results (so the result of a prior PNG request doesn't get served up for a PDF request, etc).

ASP.NET provides server side caching, and you may want to specify (in the ASPX page) <%@ OutputCache VaryByParam="*" %> so that the server caches different data for http://site/page.aspx?var=1 vs. http://site/page.aspx?var=2

But (here's the head-slapping bit):
The ASP.NET VaryByParam directive has nothing to do with the HTTP Vary header, which controls varying by other HTTP headers.Even if you have a header of Vary: * it can't prevent client-side caching based on POSTed data, since that isn't included in the HTTP…