Make sure to evict expired objects
MODIFY
WalletWasabi.Gui/Global.cs
WalletWasabi.Gui/Global.cs
@@ -118,7 +118,11 @@ namespace WalletWasabi.Gui
try
{
- Cache = new MemoryCache(new MemoryCacheOptions { SizeLimit = 1_000 });
+ Cache = new MemoryCache(new MemoryCacheOptions
+ {
+ SizeLimit = 1_000,
+ ExpirationScanFrequency = TimeSpan.FromSeconds(30)
+ });
BitcoinStore = new BitcoinStore();
var bstoreInitTask = BitcoinStore.InitializeAsync(Path.Combine(DataDir, "BitcoinStore"), Network);
var addressManagerFolderPath = Path.Combine(DataDir, "AddressManager");

MODIFY
WalletWasabi/Wallets/SmartBlockProvider.cs
WalletWasabi/Wallets/SmartBlockProvider.cs
@@ -36,8 +36,8 @@ namespace WalletWasabi.Wallets
var cacheEntryOptions = new MemoryCacheEntryOptions()
.SetSize(10)
- // There is a block every 10 minutes in average so, keep in cache for 4 seconds.
- .SetAbsoluteExpiration(TimeSpan.FromSeconds(4));
+ .SetSlidingExpiration(TimeSpan.FromSeconds(4))
+ .RegisterPostEvictionCallback(callback: EvictionCallback, state: this);;
// Save data in cache.
Cache.Set(cacheKey, getBlockTask, cacheEntryOptions);
@@ -45,5 +45,14 @@ namespace WalletWasabi.Wallets
return getBlockTask;
}
}
+
+ private void EvictionCallback(object key, object value, EvictionReason reason, object state)
+ {
+ var task = value as Task<Block>;
+ if (task.IsCompleted)
+ {
+ task?.Dispose();
+ }
+ }
}
}
\ No newline at end of file

Make sure to evict expired objects