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