数据缓存

// Web.config 配置信息 <appSettings> <add key="DataDAL" value="SQLServerDAC"/> <add key="NavCacheDuration" value="2" /> <add key="EnableCaching" value="true" /> </appSettings> //引用 using System.Web.Caching; // 获取配置信息 #region 配置文件-配置项 private static readonly int NavTimeout = int.Parse(ConfigurationManager.AppSettings["NavCacheDuration"]); private static readonly bool enableCaching = bool.Parse(ConfigurationManager.AppSettings["EnableCaching"]); #endregion // 缓存函数 #region 获取字典缓存 +static List<MODDictionary_itme> GetDicItem(bool bRenew) /// <summary> /// 获取字典缓存 /// </summary> /// <param name="bRenew">是否更新</param> /// <returns></returns> public static List<MODDictionary_itme> GetDicItem(bool bRenew) { if (!enableCaching) { return BLLDictionary_itme.GetDataModel(""); } string key = "DicItem_all"; List<MODDictionary_itme> listdata = (List<MODDictionary_itme>)HttpRuntime.Cache[key]; // Check if the data exists in the data cache if (listdata == null || bRenew) { // If the data is not in the cache then fetch the data from the business logic tier listdata = BLLDictionary_itme.GetDataModel(""); // Store the output in the data cache, and Add the necessary AggregateCacheDependency object if (bRenew) HttpRuntime.Cache.Remove(key); HttpRuntime.Cache.Add(key, listdata, null, DateTime.Now.AddHours(NavTimeout), Cache.NoSlidingExpiration, CacheItemPriority.High, null); } return listdata; } #endregion // 使用 获取缓存信息 List<MODDictionary_itme> rlist = CacheManager.GetDicItem(false); // 使用 查询缓存 使用Linq语句 txtType.Value = rlist.Find(m => m.IDic_code == 13 && m.CItem_value.ToString() == TheMod.IType.ToString()).CItem_name;
数据缓存,涉及Linq语句

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.