using Microsoft.Extensions.DependencyInjection;

namespace GxPress.Api.ServiceExtensions
{
    public static class CachingExtension
    {
        public static IServiceCollection AddDistributedCache(this IServiceCollection services, string cacheConnectionString)
        {
            var isSettings = false;
            if (!string.IsNullOrEmpty(cacheConnectionString))
            {
                isSettings = true;
                services.AddStackExchangeRedisCache(options =>
                {
                    options.Configuration = cacheConnectionString;
                    options.InstanceName = "";
                });
            }

            if (!isSettings)
            {
                services.AddDistributedMemoryCache();
            }
            return services;
        }
    }
}