您的位置:首页 > 编程语言 > ASP

asp.net2.0 缓存:数据库依赖

2007-03-29 15:19 555 查看
Web.config

<configuration>

<appSettings/>

<connectionStrings>
<add name="TestConnectionString" connectionString="server=shgpc150\sql2k;database=Northwind;uid=sa;pwd=;"></add>
</connectionStrings>

<system.web>
<caching>
<sqlCacheDependency enabled="true" pollTime="1000">
<databases>
<add name="Northwind" connectionStringName="TestConnectionString" pollTime="1000"></add>
</databases>
</sqlCacheDependency>
</caching>
............

Page_Load.

System.Web.Caching.SqlCacheDependencyAdmin.EnableNotifications(System.Configuration.ConfigurationManager.ConnectionStrings["TestConnectionString"].ConnectionString);
System.Web.Caching.SqlCacheDependencyAdmin.EnableTableForNotifications(System.Configuration.ConfigurationManager.ConnectionStrings["TestConnectionString"].ConnectionString, "Employees");

if (HttpContext.Current.Cache["dsEmpployees"] == null)
{
System.Web.Caching.SqlCacheDependency depe = new System.Web.Caching.SqlCacheDependency("Northwind", "Employees");
HttpContext.Current.Cache.Insert("dsEmpployees", "dsEmpployees", depe);
Label1.Text = "new cache generated!";
}
else
{
Label1.Text = "Load data from cache";
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: