public string GetSysConfigByKey(string key) { if (object.Equals(HttpContext.Current.Cache["Cache_SysConfig"], null)) { this.LoadSysConfigToCache(); } Hashtable hashtable = (Hashtable)HttpContext.Current.Cache["Cache_SysConfig"]; if (hashtable.ContainsKey(key)) { return hashtable[key].ToString(); } return ""; }
写入缓存
public void LoadSysConfigToCache() { try { if (object.Equals(HttpContext.Current.Cache["Cache_SysConfig"], null)) { DataTable allSysConfig = new SysConfigBLL().GetAllSysConfig(); Hashtable hashtable = new Hashtable(); foreach (DataRow row in allSysConfig.Rows) { hashtable.Add(row["ConfigKey"].ToString(), row["ConfigValue"].ToString()); } HttpContext.Current.Cache.Insert("Cache_SysConfig", hashtable); } } catch (Exception exception) { ExceptionLogFactory.CreateObject(enuExceptionType.File, exception); throw; } }
时间: 2024-11-03 17:24:57