Cache缓存

来源:互联网 发布:现代诗歌 知乎 编辑:程序博客网 时间:2024/05/17 02:19
            int cacheOutTime = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["CacheOutTime"]);


            List<Student> listModel = new List<Student>();
            Cache cache = HttpRuntime.Cache;
            string cacheItemMo = "Community";
            if (cache[cacheItemMo] == null )
            {
                listModel = GetList();
                cache.Insert(cacheItemMo, listModel, null, DateTime.Now.AddSeconds(cacheOutTime), Cache.NoSlidingExpiration);
            }
            else
            {
                listModel = cache[cacheItemMo] as List<Student>;
                if (listModel == null )
                {
                    listModel =  GetList();
                    cache.Insert(cacheItemMo, listModel, null, DateTime.Now.AddSeconds(cacheOutTime), Cache.NoSlidingExpiration);
                }
            }
0 0