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:
http://www.mywebsite.com/mypage.aspx?catalogId=10 ==> version 1
http://www.mywebsite.com/mypage.aspx?catalogId=102 ==> version 2
http://www.mywebsite.com/mypage.aspx?catalogId=1010 ==> 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.
Friday, June 1, 2007
ASP .NET Page Caching
Subscribe to:
Post Comments (Atom)
1 comment:
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..
Post a Comment