diff --git a/FastCache/FastCache.cs b/FastCache/FastCache.cs index db0bb93..0e7ca8f 100644 --- a/FastCache/FastCache.cs +++ b/FastCache/FastCache.cs @@ -14,6 +14,7 @@ public class FastCache : IEnumerable>, { private readonly ConcurrentDictionary _dict = new ConcurrentDictionary(); + private readonly Lock _lock = new(); private readonly Timer _cleanUpTimer; private readonly EvictionCallback _itemEvicted; @@ -61,7 +62,7 @@ await _globalStaticLock.WaitAsync() public void EvictExpired() { //Eviction already started by another thread? forget it, lets move on - if (Monitor.TryEnter(_cleanUpTimer)) //use the timer-object for our lock, it's local, private and instance-type, so its ok + if (_lock.TryEnter()) //use the timer-object for our lock, it's local, private and instance-type, so its ok { List evictedKeys = null; // Batch eviction callbacks try @@ -86,7 +87,7 @@ public void EvictExpired() } finally { - Monitor.Exit(_cleanUpTimer); + _lock.Exit(); } // Trigger batched eviction callbacks outside the loop to prevent flooding the thread pool diff --git a/FastCache/FastCache.csproj b/FastCache/FastCache.csproj index 5d2b925..49f01c5 100644 --- a/FastCache/FastCache.csproj +++ b/FastCache/FastCache.csproj @@ -1,30 +1,38 @@  - - net6.0;net8.0 - Jitbit.FastCache - FastCache - Alex from Jitbit - FastCache - https://github.com/jitbit/fastcache - README.md - https://github.com/jitbit/fastcache - LICENSE - 1.1.0 - cache;caching;MemoryCache - Fastest in-memoery cache for .NET - True - + + net6.0;net8.0;net9.0 + latest + Jitbit.FastCache + FastCache + Alex from Jitbit + FastCache + https://github.com/jitbit/fastcache + README.md + https://github.com/jitbit/fastcache + LICENSE + 1.1.0 + cache;caching;MemoryCache + Fastest in-memoery cache for .NET + True + - - - True - \ - - - True - \ - - + + + True + \ + + + True + \ + + + + + + all + analyzers + +