Skip to content

Commit

Permalink
awaitable full clean
Browse files Browse the repository at this point in the history
  • Loading branch information
Aleksei Troepolskii committed May 26, 2023
1 parent 34cf7b7 commit 708f6b9
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/FastCache.Cached/CacheManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,27 @@ public static class CacheManager
/// </summary>
public static void QueueFullClear<K, V>() where K : notnull
{
Task.Run(async static () =>
{
var evictionJob = CacheStaticHolder<K, V>.EvictionJob;
await evictionJob.FullEvictionLock.WaitAsync();
Task.Run(static () => FullCleanAsync<K, V>());
}

public static async Task FullCleanAsync<K, V>() where K : notnull
{
var evictionJob = CacheStaticHolder<K, V>.EvictionJob;
await evictionJob.FullEvictionLock.WaitAsync();

#if FASTCACHE_DEBUG
var countBefore = CacheStaticHolder<K, V>.Store.Count;
#endif

CacheStaticHolder<K, V>.Store.Clear();
CacheStaticHolder<K, V>.QuickList.Reset();
CacheStaticHolder<K, V>.Store.Clear();
CacheStaticHolder<K, V>.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<K, V>.QuickList.AtomicCount}/{CacheStaticHolder<K, V>.Store.Count}");
#endif
});
}

/// <summary>
Expand Down

0 comments on commit 708f6b9

Please sign in to comment.