Welcome to Bangladesh Microsoft Technology Community Sign in | Join | Help

Cache Invalidation for Dynamic pages in Asp.net 2.0

Asp.net 2.0 supports database cache dependencies. So changes in the Tables data can be notified and cache can expire. This is a very handy feature.

Here is how we can do this

<@ outputcache duration= "7200" varybyparam="CustomerID" sqldependency="DatabaseName:Customer" %>

this means the cached page expires in 2 hours but also depends on database table. Any changes on the database table data will also invalidate the cache.

Borrowed the following code from this link: Link to Improved Caching in ASP.NET 2.0

<%@ OutputCache SqlDependency="Pubs:Titles" Duration="6000" VaryByParam="none" %>

<html>
<head runat="server">

<title>Output Cache Titles</title>

</head>

<body>

<form id="form1" runat="server"> <%= DateTime.Now %>

<asp:GridView ID="grdTitles" DataSourceID="SqlDataSource1" Runat="Server" />

<asp:SqlDataSource ID="SqlDataSource1" SelectCommand="Select * FROM Titles" ConnectionString="<%$ ConnectionStrings:mySqlServer %>" Runat="Server" />

</form>

</body>

</html>

Published Thursday, November 16, 2006 3:21 AM by Shahed

Comments

No Comments

Anonymous comments are disabled