日期:2014-05-18  浏览次数:20387 次

缓存失效问题
SqlCacheDependency 缓存失效问题:

有如下代码:
  string key = "Customer_by_Id_" + customerId;
  IList<CustomerInfo> data= (IList<CustomerInfo>)HttpRuntime.Cache[key];
  // Check if the data exists in the data cache
  if (data == null) {
  data = customer.GetCustomersById(customerId);
   
  AggregateCacheDependency cd = DependencyFacade.GetCustomerDependency();

  HttpRuntime.Cache.Add(key, data, cd, DateTime.Now.AddHours(12), Cache.NoSlidingExpiration, CacheItemPriority.High, null);
  }
我的数据库表在运行中并没有更新,但在单步调试时经常会发生data为null的情况,不清楚是什么原因使Cache失效?是否是内存不足,asp.net 自动把data 调出缓存?

------解决方案--------------------
重载NotifyDependencyChanged,在调用父类方法时加入自己的日志。