using PostFundManagement.Application.Abstractions; using PostFundManagement.Application.Abstractions.Services; using PostFundManagement.Application.Services.Shared; namespace PostFundManagement.Application.Services.Tools; public sealed class ToolCacheService(ToolService service, IDistributedCache cache) : ServiceCacheBase, IToolService { public async ValueTask> EncodeLong(long id, CancellationToken cancellationToken) => await Result.Try((Func>>)(async () => { var cacheKey = HashService.ToMd5Hash($"encodelonghash-{id}").Value; var cached = await cache.GetStringAsync(cacheKey, cancellationToken); if(string.IsNullOrWhiteSpace(cached)) { var result = (await service.EncodeLong(id).ConfigureAwait(false)); if (result.IsFailed) return result; await cache.SetStringAsync(cacheKey, result.Value, cacheOptions, cancellationToken); return result.Value; } return Result.Ok(cached); })); }