MireaBackend/Endpoint/Configuration/Core/Startup/CacheConfiguration.cs

26 lines
935 B
C#
Raw Normal View History

2024-06-01 10:53:21 +03:00
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
2024-10-07 02:13:35 +03:00
using Mirea.Api.Endpoint.Configuration.Model;
2024-10-07 02:25:36 +03:00
using Mirea.Api.Endpoint.Configuration.Model.GeneralSettings;
2024-06-01 10:53:21 +03:00
2024-10-07 02:13:35 +03:00
namespace Mirea.Api.Endpoint.Configuration.Core.Startup;
2024-06-01 10:53:21 +03:00
public static class CacheConfiguration
{
2024-10-25 02:36:39 +03:00
public static IServiceCollection AddCustomRedis(this IServiceCollection services, IConfiguration configuration, IHealthChecksBuilder? healthChecksBuilder = null)
2024-06-01 10:53:21 +03:00
{
2024-06-01 11:10:42 +03:00
var cache = configuration.Get<GeneralConfig>()?.CacheSettings;
2024-10-25 02:36:39 +03:00
if (cache?.TypeDatabase != CacheSettings.CacheEnum.Redis)
return services;
services.AddStackExchangeRedisCache(options =>
2024-06-01 10:53:21 +03:00
{
2024-10-25 02:36:39 +03:00
options.Configuration = cache.ConnectionString;
options.InstanceName = "mirea_";
});
healthChecksBuilder?.AddRedis(cache.ConnectionString!, name: "Redis");
2024-06-01 10:53:21 +03:00
return services;
}
}