MemoryCache的使用

 using System.Runtime.Caching;

MemoryCache mc = MemoryCache.Default; string cacheKey = "mykey";   var value = ""; if (mc.Contains(cacheKey)) { var cacheItem = mc.Get(cacheKey); value = cacheItem as string; } else {  value = "5555";   CacheItemPolicy policy = new CacheItemPolicy(); policy.AbsoluteExpiration = DateTime.Now.AddMinutes(100); mc.Add(cacheKey, value , policy); }

 

posted @ 2018-12-18 09:44  你二哥  阅读(82)  评论(0编辑  收藏  举报