public void HighSpeedSendAndBuffCountTest_2000_Instance() { int capacity = ChannelConst.BuffAsyncStubPool.Capacity; Console.WriteLine("Initialized capacity: " + capacity); InnerHightSpeedSendTest(2000, 1000000, 20009); FixedCacheContainer <SocketBuffStub> container = (FixedCacheContainer <SocketBuffStub>)ChannelConst.BuffAsyncStubPool; Assert.IsNotNull(container); Thread.Sleep(2000); Console.WriteLine("Exactlly internal cache count: " + container.GetCount()); Assert.IsTrue(capacity == container.GetCount()); }
/// <summary> /// 租借一个新的固态缓存容器 /// </summary> /// <typeparam name="T">缓存对象类型</typeparam> /// <param name="category">分类名称</param> /// <param name="capacity">最大容量</param> /// <returns>返回缓存容器</returns> /// <exception cref="ArgumentNullException">参数不能为空</exception> /// <exception cref="ArgumentException">非法的参数取值范围</exception> public IFixedCacheContainer <T> Rent <T>(string category, int capacity) where T : IClearable, new() { if (string.IsNullOrEmpty(category)) { throw new ArgumentNullException(nameof(category)); } if (capacity <= 0) { throw new ArgumentException("Illelgal capacity!"); } lock (_lockObj) { object obj; //already has this container. if (_containers.TryGetValue(category, out obj)) { return((IFixedCacheContainer <T>)obj); } IFixedCacheContainer <T> container = new FixedCacheContainer <T>(capacity); container.BuildPerformanceCounter(category); _containers.Add(category, container); return(container); } }