public void Parallel_Add(int capacity) { var memoryCache = BoundedMemoryCache.CreateLRU <string, TestCacheItem>(capacity); var keys = new ConcurrentBag <string>(); FillCache(capacity * 4, memoryCache, keys); Assert.AreEqual(capacity, GetCacheCount(memoryCache, keys)); }
public void Parallel_Remove(int capacity) { var memoryCache = BoundedMemoryCache.CreateLRU <string, TestCacheItem>(capacity); var keys = new ConcurrentBag <string>(); FillCache(capacity, memoryCache, keys); var partitionSize = (capacity / 4) > 0 ? capacity / 4 : 1; var count = capacity; var allKeys = new ConcurrentBag <string>(keys.ToArray()); while (keys.Count > 0) { Parallel.For(0, partitionSize, _ => { if (keys.TryTake(out var key)) { memoryCache.Remove(key); } //移除不存在的 memoryCache.Remove(Guid.NewGuid().ToString()); });
public void Invalid_Capacity(int capacity) { Assert.ThrowsException <ArgumentOutOfRangeException>(() => BoundedMemoryCache.CreateLRU <string, TestCacheItem>(capacity)); }
/// <summary> /// <inheritdoc cref="LRUHotDataCache"/> /// </summary> /// <param name="capacity">容量</param> public LRUHotDataCache(int capacity) { _boundedMemoryCache = BoundedMemoryCache.CreateLRU <string, ResponseCacheEntry>(capacity); }