using System.Text.Json; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using StellaOps.Messaging.Abstractions; namespace StellaOps.Messaging.Transport.Valkey; /// /// Factory for creating Valkey distributed cache instances. /// 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 }; } /// public string ProviderName => "valkey"; /// public IDistributedCache Create(CacheOptions options) { ArgumentNullException.ThrowIfNull(options); return new ValkeyCacheStore( _connectionFactory, options, _loggerFactory?.CreateLogger>(), _jsonOptions); } /// public IDistributedCache Create(CacheOptions options) { ArgumentNullException.ThrowIfNull(options); return new ValkeyCacheStore( _connectionFactory, options, _loggerFactory?.CreateLogger>(), _jsonOptions); } }