wcf 缓存

  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

posted @ 2014-08-13 10:34  zhh  阅读(639)  评论(0编辑  收藏  举报