日期:2014-05-17 浏览次数:20500 次
if (!IsPostBack) { //System.Web.Caching.SqlCacheDependencyAdmin.EnableTableForNotifications(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString, "Articles"); string key = "test"; DataTable data = (DataTable)HttpRuntime.Cache[key]; // Check if the data exists in the data cache if (data == null) { string strSql = "select top 5 * from Articles"; // If the data is not in the cache then fetch the data from the business logic tier data = HMBase.Data.SqlHelper.ExecuteSqlToTable(strSql); // Create a AggregateCacheDependency object from the factory AggregateCacheDependency cd = new AggregateCacheDependency(); cd.Add(new SqlCacheDependency("HMWeb", "Articles")); // Store the output in the data cache, and Add the necessary AggregateCacheDependency object HttpRuntime.Cache.Add(key, data, cd, DateTime.Now.AddMinutes(2), Cache.NoSlidingExpiration, CacheItemPriority.High, null); } GridView1.DataSource = data; GridView1.DataBind(); }