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

24 lines
822 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.ConfigurationChecks.Settings;
using Mirea.Api.Endpoint.Configuration.Model;
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
{
public static IServiceCollection AddCustomRedis(this IServiceCollection services, IConfiguration configuration)
{
2024-06-01 11:10:42 +03:00
var cache = configuration.Get<GeneralConfig>()?.CacheSettings;
2024-06-01 10:53:21 +03:00
if (cache?.TypeDatabase == CacheSettings.CacheEnum.Redis)
{
services.AddStackExchangeRedisCache(options =>
{
options.Configuration = cache.ConnectionString;
options.InstanceName = "mirea_";
});
}
return services;
}
}