private CacheInfo GetCacheInfo(PortalCacheSettingsDto cacheSettingsDto, out CacheProviders provider) { provider = CacheProviders.Memory; if (!Enum.TryParse(cacheSettingsDto.CacheProvider, out provider)) { throw new ValidationException($"{provider} is not supported"); } CacheInfo result = null; if (provider == CacheProviders.Redis) { var cacheProvider = _cacheProviderResolver(); if (string.IsNullOrWhiteSpace(cacheSettingsDto.CacheHost)) { throw new ValidationException("Host cannot be an empty string"); } result = new CacheInfo(CacheProviders.Redis, cacheSettingsDto.CacheHost, cacheSettingsDto.CachePort, cacheSettingsDto.CacheUseSsl, cacheSettingsDto.CachePassword); } else { result = new CacheInfo(CacheProviders.Memory, "", 0); } return(result); }
public PortalCacheSettingsDto GetCacheSettings() { var rohamConfigs = _rohamConfigsResolver(); var cacheProvider = _cacheProviderResolver(); string cacheHost = "", cachePassword = ""; int cachePort = 0; bool cacheUseSsl = false; if (rohamConfigs.CacheProvider == CacheProviders.Redis) { var cacheInfo = cacheProvider.CreateInfo(CacheProviders.Redis, rohamConfigs.CacheConnectionString); cacheHost = cacheInfo.Host; cachePassword = cacheInfo.Password; cachePort = cacheInfo.Port; cacheUseSsl = cacheInfo.Ssl; } var result = new PortalCacheSettingsDto { ExtCacheEnabled = rohamConfigs.CacheProvider == CacheProviders.Redis, CacheProvider = rohamConfigs.CacheProvider.ToString(), CacheHost = cacheHost, CachePort = cachePort, CachePassword = cachePassword, CacheUseSsl = cacheUseSsl, AvailableCacheProviders = new List <KeyValuePair <string, string> > { new KeyValuePair <string, string>(CacheProviders.Memory.ToString(), "Memory"), new KeyValuePair <string, string>(CacheProviders.Redis.ToString(), "Redis"), } }; return(result); }
public ResultDto CheckCache(PortalCacheSettingsDto cacheSettingsDto) { return(Result(() => { CacheProviders provider; string cacheConnectionString = ""; var cacheInfo = GetCacheInfo(cacheSettingsDto, out provider); TestCacheConnection(cacheInfo, out cacheConnectionString); })); }
public ResultDto ResetCache(PortalCacheSettingsDto cacheSettingsDto) { return(Result(() => { CacheProviders provider; string cacheConnectionString = ""; var cacheInfo = GetCacheInfo(cacheSettingsDto, out provider); TestCacheConnection(cacheInfo, out cacheConnectionString); _cacheServiceResolver().Refresh(); })); }
public ResultDto SaveCacheSettings(PortalCacheSettingsDto cacheSettingsDto) { return(Result(() => { var rohamConfigs = _rohamConfigsResolver(); var rohamConfigsUpdater = rohamConfigs as IRohamConfigsUpdater; CacheProviders provider; string cacheConnectionString = ""; var cacheInfo = GetCacheInfo(cacheSettingsDto, out provider); TestCacheConnection(cacheInfo, out cacheConnectionString); rohamConfigsUpdater.SetCacheProvider(provider.ToString(), cacheConnectionString); // Clear cache if required _cacheServiceResolver().Refresh(); })); }