From 0a7df07d115060f2643fc3bdbea821d1f8044bc6 Mon Sep 17 00:00:00 2001 From: Aleksey Troepolskiy Date: Fri, 26 May 2023 13:17:07 +0300 Subject: [PATCH] Add ExecuteFullClear (#45) * awaitable full clean * FullEviction * remove FullEviction --------- Co-authored-by: Aleksei Troepolskii --- src/FastCache.Cached/CacheManager.cs | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/FastCache.Cached/CacheManager.cs b/src/FastCache.Cached/CacheManager.cs index 098eab8..ee72ae6 100644 --- a/src/FastCache.Cached/CacheManager.cs +++ b/src/FastCache.Cached/CacheManager.cs @@ -26,25 +26,31 @@ public static class CacheManager /// public static void QueueFullClear() where K : notnull { - Task.Run(async static () => - { - var evictionJob = CacheStaticHolder.EvictionJob; - await evictionJob.FullEvictionLock.WaitAsync(); + Task.Run(static () => ExecuteFullClear()); + } + + /// + /// Remove all cache entries of type Cached[K, V] from the cache + /// + /// A task that completes upon full clear execution. + public static async Task ExecuteFullClear() where K : notnull + { + var evictionJob = CacheStaticHolder.EvictionJob; + await evictionJob.FullEvictionLock.WaitAsync(); #if FASTCACHE_DEBUG var countBefore = CacheStaticHolder.Store.Count; #endif - CacheStaticHolder.Store.Clear(); - CacheStaticHolder.QuickList.Reset(); + CacheStaticHolder.Store.Clear(); + CacheStaticHolder.QuickList.Reset(); - evictionJob.FullEvictionLock.Release(); + evictionJob.FullEvictionLock.Release(); #if FASTCACHE_DEBUG Console.WriteLine( $"FastCache: Cache has been fully cleared for {typeof(K).Name}:{typeof(V).Name}. Was {countBefore}, now {CacheStaticHolder.QuickList.AtomicCount}/{CacheStaticHolder.Store.Count}"); #endif - }); } ///