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)
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?