Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET Response.Cache.SetNoStore() vs. Response.Cache.SetNoServerCaching()

Can anyone break down what these two methods do at a HTTP level.

We are dealing with Akamai edge-caching and have been told that SetNoStore() will cause can exclusion so that (for example) form pages will always post back to the origin server. According to {guy} this sets the HTTP header:

Cache-Control: "no-cache, no-store"

As I was implementing this change to our forms I found SetNoServerCaching(). Well that seems to make a bit more sense semantically, and the documentation says "Explicitly denies caching of the document on the origin-server."

So I went down to the sea sea sea to see what I could see see see. I tried both of these methods and reviewed the headers in Firebug and Fiddler.

And from what I can tell, both these method set the exact same Http Header.

Can anyone explain if there are actual differences between these methods and if so, where are hiding in the http response?!

like image 200
misteraidan Avatar asked Nov 24 '11 23:11

misteraidan


1 Answers

Theres a few differences,

SetNoStore, essentially stops the browser (and any network resource such as a CDN) from saving any part of the response or request, that includes saving to temp files. This will set the NO-STORE HTTP 1.1 header

SetNoServerCaching, will essentially stop the server from saving files, in ASP.NET There are several levels of caching that can happen, Data only, Partial Requests, Full Pages, and SQL Data. This call should stop the HTTP (Full and Partial) requests being saved on the server. This method should not set the cache-control headers or no-store or no cache.

There is also

Response.Cache.SetCacheability(HttpCacheability.Public);
Response.Cache.SetMaxAge(new TimeSpan(1, 0, 0));

as a possible way of setting cache, this will set the content-expires header.

For a CDN you probably want to set the content-expires header so that he CDN knows when to fetch new content, it if it gets a HIT. You probably don't want no-cache or no-store as this would cause a refetch on every HIT so essentially you are nullifying any benefit the CDN brings to you except they may have a faster backbone connection to the end user than your current ISP but that would be marginal.

like image 73
John Mitchell Avatar answered Sep 24 '22 10:09

John Mitchell