Files
lux/EgwCoreLib.Lux.Data/Services/Utils/CounterService.cs
T
2026-05-29 19:21:45 +02:00

55 lines
1.6 KiB
C#

namespace EgwCoreLib.Lux.Data.Services.Utils
{
public class CounterService : BaseServ, ICounterService
{
#region Public Constructors
public CounterService(
IConfiguration config,
IConnectionMultiplexer redis,
ICounterRepository repo) : base(config, redis)
{
_className = "Counter";
_repo = repo;
}
#endregion Public Constructors
#region Public Methods
/// <inheritdoc />
public async Task<List<CounterModel>> GetAllAsync(int? yearRef = null)
{
return await TraceAsync($"{_className}.GetAllAsync", async (activity) =>
{
return await GetOrSetCacheAsync(
$"{_redisBaseKey}:{_className}:ALL:Y{yearRef}",
async () => await _repo.GetAllAsync(yearRef),
FastCache
);
});
}
/// <inheritdoc />
public async Task<int> GetNextAsync(int yearRef, string countName)
{
return await TraceAsync($"{_className}.GetNextAsync", async (activity) =>
{
return await GetOrSetCacheAsync(
$"{_redisBaseKey}:{_className}:{countName}:Y{yearRef}",
async () => await _repo.GetNextAsync(yearRef, countName),
UltraFastCache
);
});
}
#endregion Public Methods
#region Private Fields
private readonly string _className;
private readonly ICounterRepository _repo;
#endregion Private Fields
}
}