From 97284592236a3e2f25203f21ab1c6564f5f86aa6 Mon Sep 17 00:00:00 2001 From: Hermes Agent Date: Fri, 4 Sep 2026 05:46:10 +0200 Subject: [PATCH 1/2] Removed client name definition on redis config --- PostFundManagement.Application/Extensions/General.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/PostFundManagement.Application/Extensions/General.cs b/PostFundManagement.Application/Extensions/General.cs index 3f3ee63..fb50e28 100644 --- a/PostFundManagement.Application/Extensions/General.cs +++ b/PostFundManagement.Application/Extensions/General.cs @@ -27,7 +27,6 @@ public static class General services.AddStackExchangeRedisCache(options => { options.Configuration = configuration.GetConnectionString("Redis"); - options.ConfigurationOptions!.ClientName = "PFM-API"; options.InstanceName = "PFM-API_"; }); -- 2.47.3 From 8ea014e4fb2909f659c5d24168bbc22081666a1e Mon Sep 17 00:00:00 2001 From: Hermes Agent Date: Fri, 4 Sep 2026 05:53:36 +0200 Subject: [PATCH 2/2] Refactored cache ttl handling --- .../Abstractions/ServiceCacheBase.cs | 9 +++++++++ .../PostFundManagement.Application.csproj | 1 + .../Communications/CommunicationsCacheService.cs | 5 +++-- .../Services/Evidence/EvidenceCacheService.cs | 5 +++-- .../Services/Shared/IdentityCacheService.cs | 6 +++--- .../Services/Users/UserCacheService.cs | 8 ++++---- 6 files changed, 23 insertions(+), 11 deletions(-) create mode 100644 PostFundManagement.Application/Abstractions/ServiceCacheBase.cs diff --git a/PostFundManagement.Application/Abstractions/ServiceCacheBase.cs b/PostFundManagement.Application/Abstractions/ServiceCacheBase.cs new file mode 100644 index 0000000..7130cf4 --- /dev/null +++ b/PostFundManagement.Application/Abstractions/ServiceCacheBase.cs @@ -0,0 +1,9 @@ +namespace PostFundManagement.Application.Abstractions; + +public abstract class ServiceCacheBase +{ + protected readonly DistributedCacheEntryOptions cacheOptions = new() + { + AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(2) + }; +} diff --git a/PostFundManagement.Application/PostFundManagement.Application.csproj b/PostFundManagement.Application/PostFundManagement.Application.csproj index b6d027c..ed7a66f 100644 --- a/PostFundManagement.Application/PostFundManagement.Application.csproj +++ b/PostFundManagement.Application/PostFundManagement.Application.csproj @@ -26,6 +26,7 @@ + diff --git a/PostFundManagement.Application/Services/Communications/CommunicationsCacheService.cs b/PostFundManagement.Application/Services/Communications/CommunicationsCacheService.cs index 611b8b5..66920ee 100644 --- a/PostFundManagement.Application/Services/Communications/CommunicationsCacheService.cs +++ b/PostFundManagement.Application/Services/Communications/CommunicationsCacheService.cs @@ -1,11 +1,12 @@ -using PostFundManagement.Application.Abstractions.Services; +using PostFundManagement.Application.Abstractions; +using PostFundManagement.Application.Abstractions.Services; using PostFundManagement.Application.Services.Shared; using PostFundManagement.Domain; using PostFundManagement.Domain.Models; namespace PostFundManagement.Application.Services.Communications; -public sealed class CommunicationsCacheService(CommunicationsService service, HybridCache cache) : ICommunicationsService +public sealed class CommunicationsCacheService(CommunicationsService service, HybridCache cache) : ServiceCacheBase, ICommunicationsService { public async ValueTask> GetApplicantInviteAsync(Guid userId, CancellationToken cancellationToken = default) => await Result.Try((Func>>)(async () => diff --git a/PostFundManagement.Application/Services/Evidence/EvidenceCacheService.cs b/PostFundManagement.Application/Services/Evidence/EvidenceCacheService.cs index 90644e6..a9db1fa 100644 --- a/PostFundManagement.Application/Services/Evidence/EvidenceCacheService.cs +++ b/PostFundManagement.Application/Services/Evidence/EvidenceCacheService.cs @@ -1,11 +1,12 @@ -using PostFundManagement.Application.Abstractions.Services; +using PostFundManagement.Application.Abstractions; +using PostFundManagement.Application.Abstractions.Services; using PostFundManagement.Application.Services.Shared; using PostFundManagement.Domain; using PostFundManagement.Domain.Models; namespace PostFundManagement.Application.Services.Evidence; -public sealed class EvidenceCacheService(EvidenceService service, HybridCache cache) : IEvidenceService +public sealed class EvidenceCacheService(EvidenceService service, HybridCache cache) : ServiceCacheBase, IEvidenceService { public async ValueTask CreateEvidenceAsync(Guid userId, IFormCollection form, IFormFile file, CancellationToken cancellationToken = default) => await service.CreateEvidenceAsync(userId, form, file, cancellationToken); diff --git a/PostFundManagement.Application/Services/Shared/IdentityCacheService.cs b/PostFundManagement.Application/Services/Shared/IdentityCacheService.cs index d635950..dbf5ea7 100644 --- a/PostFundManagement.Application/Services/Shared/IdentityCacheService.cs +++ b/PostFundManagement.Application/Services/Shared/IdentityCacheService.cs @@ -1,10 +1,10 @@ -using Microsoft.Extensions.Caching.Distributed; +using PostFundManagement.Application.Abstractions; using PostFundManagement.Application.Abstractions.Services; using PostFundManagement.Domain.Errors; namespace PostFundManagement.Application.Services.Shared; -public sealed class IdentityCacheService(IdentityService service, IDistributedCache cache) : IIdentityService +public sealed class IdentityCacheService(IdentityService service, IDistributedCache cache) : ServiceCacheBase, IIdentityService { public async ValueTask UserIsAuthorisedAsync(Guid userId, CancellationToken cancellationToken = default) => await Result.Try((Func>)(async () => @@ -19,7 +19,7 @@ public sealed class IdentityCacheService(IdentityService service, IDistributedCa if (result.IsFailed) return result; - await cache.SetStringAsync(cacheKey, "true", cancellationToken); + await cache.SetStringAsync(cacheKey, "true", cacheOptions, cancellationToken); return Result.Ok(); } diff --git a/PostFundManagement.Application/Services/Users/UserCacheService.cs b/PostFundManagement.Application/Services/Users/UserCacheService.cs index 992bd29..fe38c85 100644 --- a/PostFundManagement.Application/Services/Users/UserCacheService.cs +++ b/PostFundManagement.Application/Services/Users/UserCacheService.cs @@ -1,4 +1,4 @@ -using Microsoft.Extensions.Caching.Distributed; +using PostFundManagement.Application.Abstractions; using PostFundManagement.Application.Abstractions.Services; using PostFundManagement.Application.Services.Shared; using PostFundManagement.Domain; @@ -6,7 +6,7 @@ using PostFundManagement.Domain.Models; namespace PostFundManagement.Application.Services.Users; -public sealed class UserCacheService(UserService service, IDistributedCache cache) : IUserService +public sealed class UserCacheService(UserService service, IDistributedCache cache) : ServiceCacheBase, IUserService { public async ValueTask> GetUserAsync(Guid userId, CancellationToken cancellationToken) => await Result.Try((Func>>)(async () => @@ -21,7 +21,7 @@ public sealed class UserCacheService(UserService service, IDistributedCache cach if (userResult.IsFailed) return userResult; - await cache.SetStringAsync(cacheKey, JsonSerializer.Serialize(userResult.Value)); + await cache.SetStringAsync(cacheKey, JsonSerializer.Serialize(userResult.Value), cacheOptions, cancellationToken); return userResult; } @@ -44,7 +44,7 @@ public sealed class UserCacheService(UserService service, IDistributedCache cach if (usersResult.IsFailed) return usersResult; - await cache.SetStringAsync(cacheKey, JsonSerializer.Serialize(usersResult.Value)); + await cache.SetStringAsync(cacheKey, JsonSerializer.Serialize(usersResult.Value), cacheOptions, cancellationToken); return usersResult; } -- 2.47.3