using OnlineSalesAutoCrop.CoreAPI.Models; using OnlineSalesAutoCrop.CoreAPI.Models.Global; using StackExchange.Redis; using System; namespace OnlineSalesAutoCrop.CoreAPI { internal class CacheConnection { private readonly EnumCacheType cacheType; private readonly Lazy lazyConnection; /// /// /// /// /// internal CacheConnection(AppSettings settings) { try { cacheType = settings.CacheType; if (cacheType == EnumCacheType.Redis && !string.IsNullOrEmpty(settings.CacheUrl)) { lazyConnection = new Lazy(() => { return ConnectionMultiplexer.Connect(settings.CacheUrl); }); } } catch (Exception e) { throw new InvalidOperationException(e.Message, e); } } /// /// /// internal ConnectionMultiplexer Connection => lazyConnection?.Value; /// /// /// internal EnumCacheType CacheType => cacheType; } }