26 lines
		
	
	
		
			887 B
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			26 lines
		
	
	
		
			887 B
		
	
	
	
		
			C#
		
	
	
	
	
	
| using Microsoft.Extensions.Configuration;
 | |
| using Microsoft.Extensions.DependencyInjection;
 | |
| using Mirea.Api.Dto.Common;
 | |
| using Mirea.Api.Endpoint.Configuration.Model;
 | |
| 
 | |
| namespace Mirea.Api.Endpoint.Configuration.Core.Startup;
 | |
| 
 | |
| public static class CacheConfiguration
 | |
| {
 | |
|     public static IServiceCollection AddCustomRedis(this IServiceCollection services, IConfiguration configuration, IHealthChecksBuilder? healthChecksBuilder = null)
 | |
|     {
 | |
|         var cache = configuration.Get<GeneralConfig>()?.CacheSettings;
 | |
|         if (cache?.TypeDatabase != CacheType.Redis)
 | |
|             return services;
 | |
| 
 | |
|         services.AddStackExchangeRedisCache(options =>
 | |
|         {
 | |
|             options.Configuration = cache.ConnectionString;
 | |
|             options.InstanceName = "mirea_";
 | |
|         });
 | |
| 
 | |
|         healthChecksBuilder?.AddRedis(cache.ConnectionString!, name: "Redis");
 | |
| 
 | |
|         return services;
 | |
|     }
 | |
| } |