Make sure to clean my dic.
MODIFY
WalletWasabi/Extensions/MemoryExtensions.cs
WalletWasabi/Extensions/MemoryExtensions.cs
using Nito.AsyncEx;
using System;
using System.Collections.Generic;
+using System.Linq;
using System.Text;
using System.Threading.Tasks;
@@ -9,6 +10,7 @@ namespace Microsoft.Extensions.Caching.Memory
public static class MemoryExtensions
{
private static Dictionary<object, AsyncLock> AsyncLocks { get; } = new Dictionary<object, AsyncLock>();
+
private static object AsyncLocksLock { get; } = new object();
public static async Task<TItem> AtomicGetOrCreateAsync<TItem>(this IMemoryCache cache, object key, Func<ICacheEntry, Task<TItem>> factory)
@@ -21,6 +23,12 @@ namespace Microsoft.Extensions.Caching.Memory
AsyncLock asyncLock;
lock (AsyncLocksLock)
{
+ // Cleanup the evicted asynclocks first.
+ foreach (var toRemove in AsyncLocks.Keys.Where(x => !cache.TryGetValue(x, out _)).ToList())
+ {
+ AsyncLocks.Remove(toRemove);
+ }
+
if (!AsyncLocks.TryGetValue(key, out asyncLock))
{
asyncLock = new AsyncLock();

Make sure to clean my dic.