Example #1
0
        // GET: Cache
        public ActionResult Index()
        {
            //自己实现缓存


            for (int i = 0; i < 5; i++)
            {
                string key     = string.Format("{0}_{1}_{2}", "Program", "Count", 13);
                int    iResult = 0;
                if (CustomCache.Exist(key))
                {
                    iResult = CustomCache.Get <int>(key);
                }
                else
                {
                    iResult = Count(13);
                    CustomCache.Add(key, iResult);
                }

                Console.WriteLine("这里是第{0}次获取数据,结果为{1}", i, Count(12));
            }

            //使用内置缓存类方法如下:
            {
                string CacheKey = "CacheKey001";
                if (CacheHelper.IsCache(CacheKey))//判断缓存是否存在
                {
                    int a = 0;
                    a = CacheHelper.GetCaChe <int>(CacheKey);//获取缓存
                }
                else
                {
                    CacheHelper.CacheOjbectLocak <int>(1, CacheKey, 0);//存入缓存
                }
            }

            return(View());
        }