C#之缓存使用

一、声明缓存变量:
 private static ObjectCache _cache = MemoryCache.Default;
        public static ObjectCache Cache
        {
            get { return _cache; }
        }


二、将变量保存至缓存:


                    CacheItemPolicy policy = new CacheItemPolicy();


                    policy.AbsoluteExpiration = DateTimeOffset.Now.AddHours(时间);


                    _cache.Add(保存名, 要保存的对象, policy);


三、从缓存取值:


 对象类型 save = Cache[保存名] as 对象类型;