HttpRuntime.Cache缓存数据
来源:互联网 发布:外国域名注册网站 编辑:程序博客网 时间:2024/04/28 12:15
public static class DataTableCaches { #region 属性方法过时记录器 2012-01-10 李云 /// <summary> /// 给静态属性设置一个过期时间——用于数据库表缓存 /// </summary> private static DateTime dTableTimer; /// <summary> /// 给静态属性设置一个过期时间——用于数据库表缓存 /// </summary> public static DateTime DTableTimer { get { return dTableTimer; } set { dTableTimer = value; } } public static int hour = 0;//web.config时间配置转换 #endregion #region 表数据缓存 public static void SetUzaiDataTabaleCache(string key, object value) { if (HttpRuntime.Cache[key] == null || DateTime.Now > DTableTimer) { if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["static_cache"]) && int.TryParse(ConfigurationManager.AppSettings["static_cache"], out hour))//是否链接外数据库Static DTableTimer = DateTime.Now.AddHours(hour);//给静态属性设置一个过期时间 else DTableTimer = DateTime.Now.AddHours(2); HttpRuntime.Cache.Insert(key, value, null, dTableTimer, TimeSpan.Zero, CacheItemPriority.Low, null); } } /// <summary> /// 表数据缓存 /// </summary> public static void SetUzaiDataTabaleCache(string key, object value, int hours) { if (HttpRuntime.Cache[key] == null || DateTime.Now > DTableTimer) { DTableTimer = DateTime.Now.AddHours(hours); HttpRuntime.Cache.Insert(key, value, null, dTableTimer, TimeSpan.Zero, CacheItemPriority.Low, null); } } #endregion }
List<TravelProductInfo> listTravelProductInfo = new List<TravelProductInfo>(); string cacheName = "TravelProductInfoSelect"; if (HttpRuntime.Cache[cacheName] == null)//没有缓存 即时查询 { List<TravelProductInfo> list = m_ProductDAL.TravelProductInfoSelect(); if (list != null && list.Count > 0) { foreach (TravelProductInfo model in list) { listTravelProductInfo.Add(new TravelProductDAL().TravelProductDetatilSelect_B5M(model)); } DataTableCaches.SetUzaiDataTabaleCache(cacheName, listTravelProductInfo, 4);//产品每4小时更新一次 } } else { listTravelProductInfo = HttpRuntime.Cache[cacheName] as List<TravelProductInfo>; }
1 0
- HttpRuntime.Cache缓存数据
- 缓存二、HttpRuntime.Cache用法
- HttpRuntime.Cache 与 static Dictionary 缓存
- 如何获取HttpRuntime.Cache缓存所有的KEY
- 求解HttpRuntime.Cache偶尔缓存丢失的问题
- HttpRuntime.Cache .Net自带的缓存类
- ASP.NET HttpRuntime.Cache缓存类使用总结
- HttpRuntime.Cache用法
- HttpContext.Cache和HttpRuntime.Cache
- HttpContext.Cache 和 HttpRuntime.Cache
- HttpContext.Cache和HttpRuntime.Cache
- HttpContext.Cache和HttpRuntime.Cache
- HttpContext.Cache和HttpRuntime.Cache
- cache 缓存 数据结构设计
- jquery cache(数据缓存)
- Cache清除缓存数据
- 8.5 数据缓存Cache
- django cache缓存数据
- blog
- include注意点
- 算法竞赛入门经典第3章【小结与习题】
- 将秒数转换成NSDate,加上时区偏移
- 1007. 素数对猜想 (20)
- HttpRuntime.Cache缓存数据
- jsp乱码解决大全
- ios 获取当前时间汇总
- 虚拟化–XenServer中Windows 7与XP多vCPU支持配置
- javascript对象
- 测试备库应用主库日志时有无using current logfile选项的区别
- Java多线程学习笔记
- java初学感谢四
- NSString-NSDate类型转换和CustomBar的总结