码迷,mamicode.com
首页 > Web开发 > 详细

asp.net pagebase获取缓存的方法

时间:2016-06-13 13:12:59      阅读:150      评论:0      收藏:0      [点我收藏+]

标签:

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

  

asp.net pagebase获取缓存的方法

标签:

原文地址:http://www.cnblogs.com/muxueyuan/p/5579964.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!