Monday, April 13, 2009

Output Cache by the book

i found the best way to implement Output Cache
we have only 2 steps to make it:

step 1
define in the Web.config some different cache profiles that u need:





<add name="profile1" duration="100" varyByParam="param1" />

<add name="profile2" duration="100" varyByParam="None" />





step 2
define in your pages the profile that u want to use:

<%@ OutputCache CacheProfile="profile1" %>

now, if we want to check if it works
all we have to is to make aspx page, and to play with his links
and check if the DateTime changed or not

<%@ OutputCache CacheProfile="profile1" %>

<html xmlns="" >


<form id="form1" runat="server">

<%= DateTime.Now.ToString() %><br />

<a href="?param1=1">1</a><br />

<a href="?param1=2">2</a><br />

<a href="?param1=3">3</a><br />




Another small tip:
for disable the OutputCache(in the development environment for example) add location="None" in the appropriate profile in the web.config in this way:

<add name="profile1" duration="100" varyByParam="param1" location="None" />

No comments: