文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>缓存处理

缓存处理

时间:2010-11-16  来源:漠北的天空

1。 Bll层;(MsgType为表名)

public class MsgType 
    {
         protected AggregateCacheDependency dependency = new AggregateCacheDependency();
        public MsgType() : base("MsgType")
        {
             dependency.Add(new SqlCacheDependency(ConfigurationManager.AppSettings   ["CacheDatabaseName"].ToString(), "MsgType"));
        }

         public AggregateCacheDependency GetDependency()
         {
             return dependency;
         }
  }

2。 调用Bll的页面层;

public IList<MsgTypeEntity> GetMsgType()
        {
                string key = "MsgType";
                IList<MsgTypeEntity> data = (IList<MsgTypeEntity>)HttpRuntime.Cache[key];

                if (data == null)
                {//缓存中不存在,则从数据库中取到缓存中。。。
                    MsgType bll = new MsgType();
                    data = bll.GetEntities<MsgTypeEntity>("");
                    AggregateCacheDependency cd = bll.GetDependency();
                    System.Web.HttpRuntime.Cache.Add(key, data, cd, DateTime.Now.AddHours(24),  Cache.NoSlidingExpiration, CacheItemPriority.High, null);
                }
                return data;

}

 

相关阅读 更多 +
排行榜 更多 +
边境警察巡逻模拟中文版下载

边境警察巡逻模拟中文版下载

角色扮演 下载
数码宝贝世界复原手机版下载

数码宝贝世界复原手机版下载

角色扮演 下载
土地抢夺者中文手机版下载

土地抢夺者中文手机版下载

策略塔防 下载