ObjectCache cache = MemoryCache.Default;
  if(cache.Contains(CacheKey))
      return (IEnumerable)cache.Get(CacheKey);
  else
    {
       var obj = repository.GetObj();
       CacheItemPolicy cacheItemPolicy = new CacheItemPolicy();
       cacheItemPolicy.AbsoluteExpiration = DateTime.Now.AddHours(1.0);
       cache.Add(CacheKey, obj , cacheItemPolicy);
       return obj ;
    }

1.MemoryCache 多服务器下不能共享,可以使用AppFabric

2.MemoryCache本身 是 thread safe,但是缓存在MemoryCache中对象可能不是threadsafe 

http://msdn.microsoft.com/en-us/library/system.runtime.caching.memorycache.aspx

http://msdn.microsoft.com/library/cc645013.aspx

相关文章:

  • 2022-01-16
  • 2021-08-27
  • 2022-12-23
  • 2022-12-23
  • 2021-07-19
  • 2021-07-11
  • 2022-02-27
猜你喜欢
  • 2022-01-17
  • 2021-06-19
  • 2021-07-22
  • 2021-10-10
  • 2022-01-11
  • 2021-08-19
  • 2022-01-06
相关资源
相似解决方案