Move IdempotencyRequestCache to `WalletWasabi` project.
MODIFY
WalletWasabi.Backend/Controllers/WabiSabiController.cs
WalletWasabi.Backend/Controllers/WabiSabiController.cs
@@ -2,8 +2,8 @@ using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
-using WalletWasabi.Backend.Controllers.WabiSabi;
using WalletWasabi.Backend.Filters;
+using WalletWasabi.Cache;
using WalletWasabi.WabiSabi.Backend.PostRequests;
using WalletWasabi.WabiSabi.Backend.Rounds;
using WalletWasabi.WabiSabi.Backend.Statistics;

MODIFY
WalletWasabi.Backend/Startup.cs
WalletWasabi.Backend/Startup.cs
@@ -12,9 +12,9 @@ using NBitcoin;
using NBitcoin.RPC;
using System.Diagnostics.CodeAnalysis;
using System.IO;
-using WalletWasabi.Backend.Controllers.WabiSabi;
using WalletWasabi.Backend.Middlewares;
using WalletWasabi.BitcoinCore.Rpc;
+using WalletWasabi.Cache;
using WalletWasabi.Helpers;
using WalletWasabi.Interfaces;
using WalletWasabi.Logging;

RENAME
WalletWasabi.Tests/UnitTests/WabiSabi/Backend/Controllers/IdempotencyRequestCacheTests.cs
WalletWasabi.Tests/UnitTests/Cache/IdempotencyRequestCacheTests.cs
@@ -2,11 +2,11 @@ using Microsoft.Extensions.Caching.Memory;
using NBitcoin;
using System.Threading;
using System.Threading.Tasks;
-using WalletWasabi.Backend.Controllers.WabiSabi;
+using WalletWasabi.Cache;
using WalletWasabi.WabiSabi.Backend.Models;
using Xunit;
-namespace WalletWasabi.Tests.UnitTests.WabiSabi.Backend.Controllers;
+namespace WalletWasabi.Tests.UnitTests.Cache;
/// <summary>
/// Tests for <see cref="IdempotencyRequestCache"/> class.

MODIFY
WalletWasabi.Tests/UnitTests/WabiSabi/Client/ArenaClientTests.cs
WalletWasabi.Tests/UnitTests/WabiSabi/Client/ArenaClientTests.cs
@@ -6,8 +6,8 @@ using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using WalletWasabi.Backend.Controllers;
-using WalletWasabi.Backend.Controllers.WabiSabi;
using WalletWasabi.BitcoinCore.Rpc;
+using WalletWasabi.Cache;
using WalletWasabi.Crypto;
using WalletWasabi.Crypto.Randomness;
using WalletWasabi.Crypto.ZeroKnowledge;

MODIFY
WalletWasabi.Tests/UnitTests/WabiSabi/Client/BobClientTests.cs
WalletWasabi.Tests/UnitTests/WabiSabi/Client/BobClientTests.cs
@@ -4,8 +4,8 @@ using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using WalletWasabi.Backend.Controllers;
-using WalletWasabi.Backend.Controllers.WabiSabi;
using WalletWasabi.Blockchain.TransactionOutputs;
+using WalletWasabi.Cache;
using WalletWasabi.Crypto.Randomness;
using WalletWasabi.Tests.Helpers;
using WalletWasabi.WabiSabi;

MODIFY
WalletWasabi.Tests/UnitTests/WabiSabi/Integration/Startup.cs
WalletWasabi.Tests/UnitTests/WabiSabi/Integration/Startup.cs
@@ -2,7 +2,7 @@ using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
-using WalletWasabi.Backend.Controllers.WabiSabi;
+using WalletWasabi.Cache;
using WalletWasabi.WabiSabi.Models.Serialization;
namespace WalletWasabi.Tests.UnitTests.WabiSabi.Integration;

RENAME
WalletWasabi.Backend/Controllers/WabiSabi/IdempotencyRequestCache.cs
WalletWasabi/Cache/IdempotencyRequestCache.cs
@@ -4,7 +4,7 @@ using System.Threading.Tasks;
using WalletWasabi.WabiSabi.Backend.Models;
using WalletWasabi.WabiSabi.Crypto;
-namespace WalletWasabi.Backend.Controllers.WabiSabi;
+namespace WalletWasabi.Cache;
public class IdempotencyRequestCache
{
@@ -33,7 +33,24 @@ public class IdempotencyRequestCache
/// and <see cref="object.Equals(object?)"/> are generated for <see langword="record"/> types automatically.
/// </typeparam>
/// <typeparam name="TResponse">Type associated with <typeparamref name="TRequest"/>. The correspondence should be 1:1 mapping.</typeparam>
- public async Task<TResponse> GetCachedResponseAsync<TRequest, TResponse>(TRequest request, ProcessRequestDelegateAsync<TRequest, TResponse> action, CancellationToken cancellationToken = default) where TRequest : notnull where TResponse : class
+ public Task<TResponse> GetCachedResponseAsync<TRequest, TResponse>(TRequest request, ProcessRequestDelegateAsync<TRequest, TResponse> action, CancellationToken cancellationToken = default)
+ where TRequest : notnull
+ {
+ MemoryCacheEntryOptions options = new()
+ {
+ AbsoluteExpiration = DateTimeOffset.UtcNow.Add(CacheTimeout),
+ };
+
+ return GetCachedResponseAsync(request, action, options, cancellationToken);
+ }
+
+ /// <typeparam name="TRequest">
+ /// <see langword="record"/>s are preferred as <see cref="object.GetHashCode"/>
+ /// and <see cref="object.Equals(object?)"/> are generated for <see langword="record"/> types automatically.
+ /// </typeparam>
+ /// <typeparam name="TResponse">Type associated with <typeparamref name="TRequest"/>. The correspondence should be 1:1 mapping.</typeparam>
+ public async Task<TResponse> GetCachedResponseAsync<TRequest, TResponse>(TRequest request, ProcessRequestDelegateAsync<TRequest, TResponse> action, MemoryCacheEntryOptions options, CancellationToken cancellationToken)
+ where TRequest : notnull
{
bool callAction = false;
TaskCompletionSource<TResponse> responseTcs;
@@ -46,7 +63,7 @@ public class IdempotencyRequestCache
{
callAction = true;
responseTcs = new();
- ResponseCache.Set(request, responseTcs, DateTimeOffset.UtcNow.Add(CacheTimeout));
+ ResponseCache.Set(request, responseTcs, options);
}
}

Move IdempotencyRequestCache to `WalletWasabi` project.