Пример #1
0
        /// 从缓存中获取表数据
        /// <summary>
        /// 从缓存中获取表数据
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public DataTable GetDataTableByKey(DataCacheKey key)
        {
            GetData(key);
            DataTable dt = DataCacheHelper.GetCache(key.ToString() + "_Table") as DataTable;

            return(dt);
        }
Пример #2
0
        /// 获取全部的区域信息
        /// <summary>
        /// 获取全部的区域信息
        /// </summary>
        /// <returns></returns>
        private List <AreaInfo> GetAllAreaInfoList()
        {
            List <AreaInfo> list = DataCacheHelper.GetCache("AllAreaInfoList") as List <AreaInfo>;

            if (list == null)
            {
                list = RefreshAllAreaInfoList();
            }
            return(list);
        }
Пример #3
0
        /// 获取数据-主入口
        /// <summary>
        /// 获取数据-主入口
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        private Dictionary <string, DataRow> GetData(DataCacheKey key)
        {
            //缓存字典
            Dictionary <string, DataRow> dic = DataCacheHelper.GetCache(key.ToString()) as Dictionary <string, DataRow>;
            DataTable dt = DataCacheHelper.GetCache(key.ToString() + "_Table") as DataTable;

            if (dic == null || dt == null)
            {
                //没有数据则查询数据,并缓存
                dic = CacheData(key);
                Loger.Log4Net.Info("缓存数据+" + key + " 数量:" + dic.Count);
            }
            return(dic);
        }
Пример #4
0
        /// 刷新全部的区域信息
        /// <summary>
        /// 刷新全部的区域信息
        /// </summary>
        /// <returns></returns>
        private List <AreaInfo> RefreshAllAreaInfoList()
        {
            //获取缓存数据
            GetData(DataCacheKey.AreaInfo_Province);
            GetData(DataCacheKey.AreaInfo_City);
            GetData(DataCacheKey.AreaInfo_County);
            //存储
            List <AreaInfo> list = new List <AreaInfo>();

            AppendAreaData(list, AreaInfo_Province.Values.ToArray(), 1);
            AppendAreaData(list, AreaInfo_City.Values.ToArray(), 2);
            AppendAreaData(list, AreaInfo_County.Values.ToArray(), 3);
            //缓存 当前晚上0点过期
            DateTime date = DateTime.Today.AddDays(1);

            DataCacheHelper.SetCache("AllAreaInfoList", list, date, System.Web.Caching.Cache.NoSlidingExpiration);
            return(list);
        }
Пример #5
0
        /// 缓存
        /// <summary>
        /// 缓存
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        private Dictionary <string, DataRow> CacheData(DataCacheKey key)
        {
            Dictionary <string, DataRow> data = new Dictionary <string, DataRow>();

            //当前晚上0点过期
            DateTime  date   = DateTime.Today.AddDays(1);
            string    keycol = "";
            DataTable dt     = GetDataFunc(key, out keycol);

            if (dt == null)
            {
                Loger.Log4Net.Info("查询出错,未缓存数据:" + key);
                return(data);
            }
            foreach (DataRow dr in dt.Rows)
            {
                data[dr[keycol].ToString()] = dr;
            }
            //缓存字典
            DataCacheHelper.SetCache(key.ToString(), data, date, System.Web.Caching.Cache.NoSlidingExpiration);
            //缓存表
            DataCacheHelper.SetCache(key.ToString() + "_Table", dt, date, System.Web.Caching.Cache.NoSlidingExpiration);
            return(data);
        }