From 3ea1ec7a286ca132a67282b3a71ed75485351743 Mon Sep 17 00:00:00 2001 From: mhkarami97 Date: Wed, 7 May 2025 09:04:46 +0330 Subject: [PATCH] fix: remove MaxCount from async lock config --- CacheManager.Redis/CacheSource/RedisCacheSource.cs | 2 +- CacheManager/CacheManager.csproj | 6 +++--- CacheManager/CacheSource/ICacheSourceBase.cs | 3 ++- CacheManager/CacheSource/ICacheSourceWithGet.cs | 2 +- .../CacheSource/ICacheSourceWithGetWithClear.cs | 4 ++-- CacheManager/CacheSource/ICacheSourceWithGetWithSet.cs | 2 +- CacheManager/Config/LockConfig.cs | 9 --------- CacheManager/EasyCacheManager.cs | 4 +++- CacheManager/IEasyCacheManager.cs | 10 +++++----- CacheManagerClear/ICachePublisher.cs | 6 +++--- CacheManagerClear/ICacheSubscriber.cs | 4 ++-- CacheManagerUnitTest/EasyCacheManagerTests.cs | 2 +- 12 files changed, 24 insertions(+), 30 deletions(-) diff --git a/CacheManager.Redis/CacheSource/RedisCacheSource.cs b/CacheManager.Redis/CacheSource/RedisCacheSource.cs index 07c4fd4..0b14c0e 100644 --- a/CacheManager.Redis/CacheSource/RedisCacheSource.cs +++ b/CacheManager.Redis/CacheSource/RedisCacheSource.cs @@ -87,7 +87,7 @@ public async Task ClearAllAsync() var server = connectionMultiplexer.GetServer(_config.ConnectionString); var pattern = $"{_keyPrefix}*"; - await foreach (var key in server.KeysAsync(pattern: pattern)) + await foreach (var key in server.KeysAsync(pattern: pattern).ConfigureAwait(false)) { _ = await _redisCache.KeyDeleteAsync(key).ConfigureAwait(false); } diff --git a/CacheManager/CacheManager.csproj b/CacheManager/CacheManager.csproj index 96d6389..346a0fc 100644 --- a/CacheManager/CacheManager.csproj +++ b/CacheManager/CacheManager.csproj @@ -18,9 +18,9 @@ public CacheManager CacheManager - 2.1.0 - 2.1.0 - 2.1.0 + 2.1.1 + 2.1.1 + 2.1.1 true MHKarami97.snk true diff --git a/CacheManager/CacheSource/ICacheSourceBase.cs b/CacheManager/CacheSource/ICacheSourceBase.cs index f46e82b..e0f2cca 100644 --- a/CacheManager/CacheSource/ICacheSourceBase.cs +++ b/CacheManager/CacheSource/ICacheSourceBase.cs @@ -11,7 +11,7 @@ public interface ICacheSourceBase : IAsyncDisposable /// Stop cache source /// /// - Task StopAsync(); + public Task StopAsync(); /// /// Priority, Lowest priority - checked last @@ -20,6 +20,7 @@ public interface ICacheSourceBase : IAsyncDisposable /// The value of should be between 1 and 100. /// [Range(1, 100)] + public #if NET8_0_OR_GREATER int Priority { get; init; } #else diff --git a/CacheManager/CacheSource/ICacheSourceWithGet.cs b/CacheManager/CacheSource/ICacheSourceWithGet.cs index 601622d..225d29c 100644 --- a/CacheManager/CacheSource/ICacheSourceWithGet.cs +++ b/CacheManager/CacheSource/ICacheSourceWithGet.cs @@ -10,5 +10,5 @@ public interface ICacheSourceWithGet : ICacheSourceBase /// /// Key /// Result - Task GetAsync(string key); + public Task GetAsync(string key); } diff --git a/CacheManager/CacheSource/ICacheSourceWithGetWithClear.cs b/CacheManager/CacheSource/ICacheSourceWithGetWithClear.cs index 9970760..3285b64 100644 --- a/CacheManager/CacheSource/ICacheSourceWithGetWithClear.cs +++ b/CacheManager/CacheSource/ICacheSourceWithGetWithClear.cs @@ -9,10 +9,10 @@ public interface ICacheSourceWithGetWithClear : ICacheSourceWithGet /// Clear from cache with key /// /// - Task ClearAsync(string key); + public Task ClearAsync(string key); /// /// Clear all from cache /// - Task ClearAllAsync(); + public Task ClearAllAsync(); } diff --git a/CacheManager/CacheSource/ICacheSourceWithGetWithSet.cs b/CacheManager/CacheSource/ICacheSourceWithGetWithSet.cs index 753cff3..6ca177a 100644 --- a/CacheManager/CacheSource/ICacheSourceWithGetWithSet.cs +++ b/CacheManager/CacheSource/ICacheSourceWithGetWithSet.cs @@ -10,5 +10,5 @@ public interface ICacheSourceWithGetWithSet : ICacheSourceWithGet /// /// Key /// Data to cache - Task SetAsync(string key, T data); + public Task SetAsync(string key, T data); } diff --git a/CacheManager/Config/LockConfig.cs b/CacheManager/Config/LockConfig.cs index 4b65b21..c9d7ddb 100644 --- a/CacheManager/Config/LockConfig.cs +++ b/CacheManager/Config/LockConfig.cs @@ -5,15 +5,6 @@ /// public class LockConfig { - /// - /// The maximum number of requests for the semaphore that can be granted concurrently. Defaults to 1. - /// -#if NET8_0_OR_GREATER - public int MaxCount { get; init; } = 1; -#else - public int MaxCount { get; set; } = 1; -#endif - /// /// The size of the pool to use in order for generated objects to be reused. This is NOT a concurrency limit, /// but if the pool is empty then a new object will be created rather than waiting for an object to return to diff --git a/CacheManager/EasyCacheManager.cs b/CacheManager/EasyCacheManager.cs index 9ba650c..e3e1514 100644 --- a/CacheManager/EasyCacheManager.cs +++ b/CacheManager/EasyCacheManager.cs @@ -58,7 +58,9 @@ public EasyCacheManager([Required] IEnumerable cacheSources _asyncLock = new AsyncKeyedLocker(new AsyncKeyedLockOptions { - PoolSize = Environment.ProcessorCount * lockConfig.PoolSize, PoolInitialFill = lockConfig.PoolInitialFill, MaxCount = lockConfig.MaxCount + PoolSize = Environment.ProcessorCount * lockConfig.PoolSize, + PoolInitialFill = lockConfig.PoolInitialFill, + MaxCount = 1 }); _ongoingOperations = new ConcurrentDictionary(); diff --git a/CacheManager/IEasyCacheManager.cs b/CacheManager/IEasyCacheManager.cs index 87e6e4a..3cb0639 100644 --- a/CacheManager/IEasyCacheManager.cs +++ b/CacheManager/IEasyCacheManager.cs @@ -10,7 +10,7 @@ public interface IEasyCacheManager : IAsyncDisposable /// /// Key /// cached item - Task GetAsync(string key); + public Task GetAsync(string key); /// /// Manual set value to cache @@ -18,22 +18,22 @@ public interface IEasyCacheManager : IAsyncDisposable /// Key /// Value /// cached item - Task SetAsync(string key, T value); + public Task SetAsync(string key, T value); /// /// Clear cached item by key /// /// Key - Task ClearCacheAsync(string key); + public Task ClearCacheAsync(string key); /// /// Clear cached item from all /// - Task ClearAllCacheAsync(); + public Task ClearAllCacheAsync(); /// /// Stop all cache sources /// /// - Task StopAsync(); + public Task StopAsync(); } diff --git a/CacheManagerClear/ICachePublisher.cs b/CacheManagerClear/ICachePublisher.cs index 313a6c9..42d0e9f 100644 --- a/CacheManagerClear/ICachePublisher.cs +++ b/CacheManagerClear/ICachePublisher.cs @@ -11,17 +11,17 @@ public interface ICachePublisher : IAsyncDisposable /// key /// CancellationToken /// - Task PublishClearCacheAsync(string key, CancellationToken? cancellationToken); + public Task PublishClearCacheAsync(string key, CancellationToken? cancellationToken); /// /// Publish clear all cached event /// /// - Task PublishClearAllCacheAsync(CancellationToken? cancellationToken); + public Task PublishClearAllCacheAsync(CancellationToken? cancellationToken); /// /// Stops the Kafka subscription process /// /// - Task StopAsync(); + public Task StopAsync(); } diff --git a/CacheManagerClear/ICacheSubscriber.cs b/CacheManagerClear/ICacheSubscriber.cs index 08e4102..cc8da4b 100644 --- a/CacheManagerClear/ICacheSubscriber.cs +++ b/CacheManagerClear/ICacheSubscriber.cs @@ -8,11 +8,11 @@ public interface ICacheSubscriber : IAsyncDisposable /// /// Subscriber for cache clear event /// - Task SubscribeAsync(CancellationToken cancellationToken); + public Task SubscribeAsync(CancellationToken cancellationToken); /// /// Stops the subscription process /// /// - Task StopAsync(); + public Task StopAsync(); } diff --git a/CacheManagerUnitTest/EasyCacheManagerTests.cs b/CacheManagerUnitTest/EasyCacheManagerTests.cs index 4cb6faa..d0e5484 100644 --- a/CacheManagerUnitTest/EasyCacheManagerTests.cs +++ b/CacheManagerUnitTest/EasyCacheManagerTests.cs @@ -11,7 +11,7 @@ public class EasyCacheManagerTests : IAsyncLifetime public Task InitializeAsync() { - _lockConfig = new LockConfig { PoolSize = 1, PoolInitialFill = 1, MaxCount = 1, TimeOut = TimeSpan.FromSeconds(5) }; + _lockConfig = new LockConfig { PoolSize = 1, PoolInitialFill = 1, TimeOut = TimeSpan.FromSeconds(5) }; return Task.CompletedTask; }