stabilizaiton work - projects rework for maintenanceability and ui livening
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace StellaOps.Provcache.Valkey;
|
||||
|
||||
public sealed partial class ValkeyProvcacheStore
|
||||
{
|
||||
public async ValueTask SetAsync(ProvcacheEntry entry, CancellationToken cancellationToken = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
var db = await GetDatabaseAsync(cancellationToken).ConfigureAwait(false);
|
||||
var redisKey = BuildKey(entry.VeriKey);
|
||||
var value = JsonSerializer.Serialize(entry, _jsonOptions);
|
||||
|
||||
var ttl = entry.ExpiresAt - _timeProvider.GetUtcNow();
|
||||
if (ttl <= TimeSpan.Zero)
|
||||
{
|
||||
_logger.LogDebug("Skipping expired entry for VeriKey {VeriKey}", entry.VeriKey);
|
||||
return;
|
||||
}
|
||||
|
||||
if (ttl > _options.MaxTtl)
|
||||
{
|
||||
ttl = _options.MaxTtl;
|
||||
}
|
||||
|
||||
await db.StringSetAsync(redisKey, value, ttl).ConfigureAwait(false);
|
||||
|
||||
_logger.LogDebug("Stored cache entry for VeriKey {VeriKey} with TTL {Ttl}", entry.VeriKey, ttl);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error storing cache entry for VeriKey {VeriKey}", entry.VeriKey);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user