MireaBackend/Endpoint/Configuration/AppConfig/CacheConfiguration.cs
2024-06-01 10:53:21 +03:00

23 lines
746 B
C#

using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Mirea.Api.Endpoint.Configuration.General.Settings;
namespace Mirea.Api.Endpoint.Configuration.AppConfig;
public static class CacheConfiguration
{
public static IServiceCollection AddCustomRedis(this IServiceCollection services, IConfiguration configuration)
{
var cache = configuration.Get<CacheSettings>();
if (cache?.TypeDatabase == CacheSettings.CacheEnum.Redis)
{
services.AddStackExchangeRedisCache(options =>
{
options.Configuration = cache.ConnectionString;
options.InstanceName = "mirea_";
});
}
return services;
}
}