This commit is contained in:
StellaOps Bot
2025-12-13 02:22:15 +02:00
parent 564df71bfb
commit 999e26a48e
395 changed files with 25045 additions and 2224 deletions

View File

@@ -0,0 +1,57 @@
using System.Text.Json;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using StellaOps.Messaging.Abstractions;
namespace StellaOps.Messaging.Transport.Valkey;
/// <summary>
/// Factory for creating Valkey distributed cache instances.
/// </summary>
public sealed class ValkeyCacheFactory : IDistributedCacheFactory
{
private readonly ValkeyConnectionFactory _connectionFactory;
private readonly ILoggerFactory? _loggerFactory;
private readonly JsonSerializerOptions _jsonOptions;
public ValkeyCacheFactory(
ValkeyConnectionFactory connectionFactory,
ILoggerFactory? loggerFactory = null,
JsonSerializerOptions? jsonOptions = null)
{
_connectionFactory = connectionFactory ?? throw new ArgumentNullException(nameof(connectionFactory));
_loggerFactory = loggerFactory;
_jsonOptions = jsonOptions ?? new JsonSerializerOptions
{
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
WriteIndented = false
};
}
/// <inheritdoc />
public string ProviderName => "valkey";
/// <inheritdoc />
public IDistributedCache<TKey, TValue> Create<TKey, TValue>(CacheOptions options)
{
ArgumentNullException.ThrowIfNull(options);
return new ValkeyCacheStore<TKey, TValue>(
_connectionFactory,
options,
_loggerFactory?.CreateLogger<ValkeyCacheStore<TKey, TValue>>(),
_jsonOptions);
}
/// <inheritdoc />
public IDistributedCache<TValue> Create<TValue>(CacheOptions options)
{
ArgumentNullException.ThrowIfNull(options);
return new ValkeyCacheStore<TValue>(
_connectionFactory,
options,
_loggerFactory?.CreateLogger<ValkeyCacheStore<TValue>>(),
_jsonOptions);
}
}