Example #1
0
            static INakedBoundedObjectPool <ExclusiveExecutingLock <ResponseCacheEntry> > CreateExclusiveExecutingLockPool(IServiceProvider serviceProvider)
            {
                var objectPoolOptions = GetObjectPoolOptions(serviceProvider);

                var lifecycleExecutor = serviceProvider.GetRequiredService <ExclusiveExecutingLockLifecycleExecutor <ResponseCacheEntry> >();
                var pool = BoundedObjectPool.Create(lifecycleExecutor, objectPoolOptions);

                return((INakedBoundedObjectPool <ExclusiveExecutingLock <ResponseCacheEntry> >)pool);
            }
Example #2
0
        /// <summary>
        /// 添加<see cref="IExecutingLockPool{TCachePayload}"/>
        /// </summary>
        /// <param name="services"></param>
        private static void AddExecutingLockPool(this IServiceCollection services)
        {
            services.TryAddSingleton(services =>
            {
                var options = services.GetRequiredService <IOptions <ResponseCachingExecutingLockOptions> >().Value;

                var boundedObjectPoolOptions = new BoundedObjectPoolOptions()
                {
                    MaximumPooled   = options.MaximumSemaphorePooled,
                    MinimumRetained = options.MinimumSemaphoreRetained,
                    RecycleInterval = options.SemaphoreRecycleInterval,
                };

                var semaphorePool = BoundedObjectPool.Create(new SinglePassSemaphoreLifecycleExecutor(), boundedObjectPoolOptions);

                return((INakedBoundedObjectPool <SemaphoreSlim>)semaphorePool);
            });

            services.TryAddSingleton(typeof(ExclusiveExecutingLockLifecycleExecutor <>));
            services.TryAddSingleton(typeof(SharedExecutingLockLifecycleExecutor <>));

            services.TryAddSingleton(serviceProvider => CreateSharedExecutingLockPool(serviceProvider));
            services.TryAddSingleton(serviceProvider => CreateExclusiveExecutingLockPool(serviceProvider));
 private void InitPool(int maximumPooled, int minimumRetained, int recycleIntervalSeconds = 60)
 {
     _boundedObjectPool = BoundedObjectPool.Create <BoundedObjectPoolTestClass>(maximumPooled, minimumRetained, recycleIntervalSeconds);
 }