Friday, June 1, 2007

ASP .NET Page Caching

ASP .NET 2.0 provides a great mechanism for page out put caching. Consider that you have a web page which is showing some information to the users. Now we want to cache this page out put for user with 60 seconds.

To achieve this goal you need just put some code in your pages like this:

<%@ OutputCache VaryByParam="None" Duration="60" %>

The OutputCache directive will create a copy of your page html output to ASP .NET Cache and from the next request to this page up to the end of Duration period the response object will return only this Html cached output. So as you see I’ve put 60 in Duration which mean that the cache duration is 60 seconds.

VaryByParam attribute is semicolon-separated list of strings used to vary the output cache. When I set it to “None” it means that this page will just have one version in its cache. But if I set it to catalogId it means that it will cache each and every page with different catalogId Query String passed. Like this: ==> version 1 ==> version 2 ==> version 3

And so on....
As I said, VaryByParam can have more that one parameters as semicolon-seperated list, like this:

<%@ OutputCache VaryByParam="None" Duration="60" %>

I will discuss more about page output cache in my next post.

1 comment:

Web development Company said...

I enjoyed reading it. I need to read more on this topic...I admiring time and effort you put in your blog, because it is obviously one great place where I can find lot of useful info..