asp.net pagebase获取缓存的方法

        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;
            }
        }

  

posted on 2016-06-13 11:09  雪原日暮  阅读(178)  评论(0编辑  收藏  举报