Switch `SmartBlockProvider` to use `IdempotencyRequestCache`.
MODIFY
WalletWasabi/Wallets/SmartBlockProvider.cs
WalletWasabi/Wallets/SmartBlockProvider.cs
@@ -2,6 +2,7 @@ using Microsoft.Extensions.Caching.Memory;
using NBitcoin;
using System.Threading;
using System.Threading.Tasks;
+using WalletWasabi.Cache;
namespace WalletWasabi.Wallets;
@@ -11,28 +12,30 @@ namespace WalletWasabi.Wallets;
/// </summary>
public class SmartBlockProvider : IBlockProvider
{
+ private static MemoryCacheEntryOptions CacheOptions = new()
+ {
+ Size = 10,
+ SlidingExpiration = TimeSpan.FromSeconds(4)
+ };
+
public SmartBlockProvider(IBlockProvider provider, IMemoryCache cache)
{
InnerBlockProvider = provider;
- Cache = cache;
+ Cache = new(cache);
}
private IBlockProvider InnerBlockProvider { get; }
- private IMemoryCache Cache { get; }
+ private IdempotencyRequestCache Cache { get; }
public async Task<Block> GetBlockAsync(uint256 blockHash, CancellationToken cancel)
{
string cacheKey = $"{nameof(SmartBlockProvider)}:{nameof(GetBlockAsync)}:{blockHash}";
- var cacheOptions = new MemoryCacheEntryOptions
- {
- Size = 10,
- SlidingExpiration = TimeSpan.FromSeconds(4)
- };
- return await Cache.AtomicGetOrCreateAsync(
+ return await Cache.GetCachedResponseAsync(
cacheKey,
- cacheOptions,
- () => InnerBlockProvider.GetBlockAsync(blockHash, cancel)).ConfigureAwait(false);
+ action: (string request, CancellationToken token) => InnerBlockProvider.GetBlockAsync(blockHash, token),
+ options: CacheOptions,
+ cancel).ConfigureAwait(false);
}
}

Switch `SmartBlockProvider` to use `IdempotencyRequestCache`.