Beispiel #1
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         var data = CacheUtil.GetCache(KeyCenter.GenJsonClass);
         if (data != null)
         {
             coderesult = data.ToString();
         }
     }
 }
Beispiel #2
0
        /// <summary>
        /// 获取数据,包含缓存(缓存有就取,没有就执行方法获取)
        /// </summary>
        /// <typeparam name="T">要获取的对象</typeparam>
        /// <param name="fn">缓存没有执行的方法</param>
        private T GetDataWithCache <T>(Func <T> fn, string key) where T : class
        {
            var cachekey  = KeyCenter.KeyStrPrefix + key;
            var cachedata = CacheUtil.GetCache(cachekey) as T;

            if (cachedata == null)
            {
                if (fn == null)
                {
                    return(null);
                }

                var fr = fn.Invoke().AsyncInsertCache(cachekey);
                return(fr);
            }

            return(cachedata);
        }