Caching is one of key items that is being discussed whenever we talk about the performance of a web application. We always to use caching as a primary tool while designing and development of a web application. ASP.NET itself supports different kind of caching for handling various scenarios. Although we talk about it a lot, but I have seen that it is not implemented properly at most of the applications
I’ll not talk about it in detail about Caching in this post. Although I wrote an article on this topic in detail on www.codeproject.com long back, you can refer it for getting more information
State management and ways to handle Cache in a Web Farm/Web Garden scenario
Note : As this post was written long back (Apr 2011) some of part of could be old and may not be relevant in the current scenarios.
Let’s comeback to the topic. There are different ways to implement caching and one of the caching technique is called Output caching. But let’s understand that what is output caching?
Output caching is a way to cache a specific page or some part of the page and whenever a request comes for that specific page, if that is available in output cache, it gets delivered from there.
IIS 7.X and 8.X provides us capability to enable output cache based on certain criteria. In normal scenario, when a page request comes to IIS, it goes first with IIS Pipeline and then further goes though ASP.NET Pipeline before the request gets served. So if we cache some items at IIS itself, then we can save the whole IIS pipeline and ASP.NET pipeline. So let’s see how to enable that.
Enable output caching at IIS
Step -1 : Go to IIS manager. (Type ‘inetmgr’ at run and press ok)
Step – 2: Select your website (where you want to enable caching) under Sites
Step -3: Go to Features View and click on Output Caching under IIS category.
Step – 4 : Select Add… from right hand pane and it will open the below window
`We need to provide the extension of the file name that we want to cache and select other options.
Here, IIS provides two options to enable caching.
1- Kernel-mode level
2- User-mode caching.
So before making any choices, let’s have a look IIS architecture at Higher level .
HTTP.sys is kernel mode device driver which act as HTTP Listener which listens HTTP and HTTPs requests directly from the network and then pass it to user mode for further processing.
If we cache something at kernel mode then it will be very fast as it picks the request direct from the network and return from here only if it is cached. It will even save the whole IIS and ASP.NET pipeline.
It provides some options while enabling it
1- File Change notifications
2- Provide time interval – Based on the provided time interval cache will be invalidated.
3- No cache
As the features of IIS is not available at kernel-mode so there is some limitation with kernel mode caching like if request needs to be authenticated then caching at kernel level would not work. There are many other cases. For full list please refer here.
User mode caching is maintained at worker process (w3wp.exe) level so it is more powerful and provide some more options than kernel mode caching.
When we click on advance button it shows the below window
It allows to cache the data based on query-string variable and headers level which is very useful in certain scenarios.
So use this fantastic feature provided by IIS and get it benefited.