Refactored cache ttl handling

This commit is contained in:
2026-09-04 05:53:36 +02:00
parent 9728459223
commit 8ea014e4fb
6 changed files with 23 additions and 11 deletions
@@ -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<Result<User>> GetUserAsync(Guid userId, CancellationToken cancellationToken) =>
await Result.Try((Func<ValueTask<Result<User>>>)(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;
}