First time here? You are looking at the most recent posts. You may also want to check out older archives or the tag cloud. Please leave a comment, ask a question and consider subscribing to the latest posts via RSS. Thank you for visiting! (hide this)

A few months ago, while still working on websites with millions of users per day, Luigi and I spent a bad evening trying to debug the cause of a sudden increase in the CPU time of our live servers.

In ASP.NET you can choose whether a page is cached by the browser or not simply setting the Cache-Control HTTP header with that code:

Response.Cache.SetCacheability(HttpCacheability.NoCache)

The SetCachability method:

Sets the Cache-Control HTTP header. The Cache-Control HTTP header controls how documents are to be cached on the network.

Going back to problem I had, I had just added a page with the live results of the match, so I set the cache to NoCache in order to force the browser to download it from the server all the times.

HttpCacheability enum on MSDN:

  • NoCache: nobody can cache the page.
  • Private: only browsers can cache it (but not shared proxies). This is the default value
  • Public: everybody can cache the page, proxies included
  • Server: pages are cached only on the server (like the NoCache, so browsers don't cache the page)
  • ServerAndNoCache: Server and NoCache... the same as Server
  • ServerAndPrivate: Server and Private... the same as Private

So why did I have the increase of the load on the server?

Because "nobody" includes also the OutputCache of the server, so my page was rebuilt with every request instead of once per minute. I simply changed to ServerAndNoCache and the load dropped immediately.

So, if you just want to disable the caching on the browser, but also want the benefit of the ASP.NET caching, forget about the NoCache and use ServerAndNoCache.

The question is why MS decided to control with the same enum both the Cache-Control HTTP header and the ASP.NET Server cache?

Maybe Brad or Krzysztof can answer that question smile_wink

posted on Sunday, April 1, 2007 11:10 PM
Comments have been closed on this topic.