/// <summary> /// Initializes a new instance of the <see cref="T:EasyCaching.HybridCache.HybridCachingProvider"/> class. /// </summary> /// <param name="name">Name.</param> /// <param name="optionsAccs">Options accs.</param> /// <param name="factory">Providers factory</param> /// <param name="bus">Bus.</param> /// <param name="loggerFactory">Logger factory.</param> public HybridCachingProvider( string name , HybridCachingOptions optionsAccs , IEasyCachingProviderFactory factory , IEasyCachingBus bus = null , ILoggerFactory loggerFactory = null ) { ArgumentCheck.NotNull(factory, nameof(factory)); this._name = name; this._options = optionsAccs; ArgumentCheck.NotNullOrWhiteSpace(_options.TopicName, nameof(_options.TopicName)); if (optionsAccs.EnableLogging) { this._logger = loggerFactory.CreateLogger <HybridCachingProvider>(); } // Here use the order to distinguish traditional provider this._localCache = factory.GetCachingProvider(_options.LocalCacheProviderName); // Here use the order to distinguish traditional provider this._distributedCache = factory.GetCachingProvider(_options.DistributedCacheProviderName); this._bus = bus ?? NullEasyCachingBus.Instance; this._bus.Subscribe(_options.TopicName, OnMessage); this._cacheId = Guid.NewGuid().ToString("N"); }
/// <summary> /// Initializes a new instance of the <see cref="T:EasyCaching.HybridCache.HybridCachingProvider"/> class. /// </summary> /// <param name="optionsAccs">Options accs.</param> /// <param name="IEasyCachingProviderFactory">Providers factory</param> /// <param name="bus">Bus.</param> /// <param name="loggerFactory">Logger factory.</param> public HybridCachingProvider( IOptions <HybridCachingOptions> optionsAccs , IEasyCachingProviderFactory factory , IEasyCachingBus bus = null , ILoggerFactory loggerFactory = null ) { ArgumentCheck.NotNull(factory, nameof(factory)); this._options = optionsAccs.Value; ArgumentCheck.NotNullOrWhiteSpace(_options.TopicName, nameof(_options.TopicName)); this._logger = loggerFactory?.CreateLogger <HybridCachingProvider>(); //Here use the order to distinguish traditional provider var local = factory.GetCachingProvider(_options.LocalCacheProviderName); if (local.IsDistributedCache) { throw new NotFoundCachingProviderException("Can not found any local caching providers."); } else { this._localCache = local; } //Here use the order to distinguish traditional provider var distributed = factory.GetCachingProvider(_options.DistributedCacheProviderName); if (!distributed.IsDistributedCache) { throw new NotFoundCachingProviderException("Can not found any distributed caching providers."); } else { this._distributedCache = distributed; } this._bus = bus ?? NullEasyCachingBus.Instance; this._bus.Subscribe(_options.TopicName, OnMessage); this._cacheId = Guid.NewGuid().ToString("N"); }
/// <summary> /// Initializes a new instance of the <see cref="T:EasyCaching.HybridCache.HybridCachingProvider"/> class. /// </summary> /// <param name="optionsAccs">Options accs.</param> /// <param name="providers">Providers.</param> /// <param name="bus">Bus.</param> /// <param name="loggerFactory">Logger factory.</param> public HybridCachingProvider( IOptions <HybridCachingOptions> optionsAccs , IEnumerable <IEasyCachingProvider> providers , IEasyCachingBus bus = null , ILoggerFactory loggerFactory = null ) { ArgumentCheck.NotNullAndCountGTZero(providers, nameof(providers)); this._options = optionsAccs.Value; ArgumentCheck.NotNullOrWhiteSpace(_options.TopicName, nameof(_options.TopicName)); this._logger = loggerFactory?.CreateLogger <HybridCachingProvider>(); //Here use the order to distinguish traditional provider var local = providers.OrderBy(x => x.Order).FirstOrDefault(x => !x.IsDistributedCache); if (local == null) { throw new NotFoundCachingProviderException("Can not found any local caching providers."); } else { this._localCache = local; } //Here use the order to distinguish traditional provider var distributed = providers.OrderBy(x => x.Order).FirstOrDefault(x => x.IsDistributedCache); if (distributed == null) { throw new NotFoundCachingProviderException("Can not found any distributed caching providers."); } else { this._distributedCache = distributed; } this._bus = bus ?? NullEasyCachingBus.Instance; this._bus.Subscribe(_options.TopicName, OnMessage); this._cacheId = Guid.NewGuid().ToString("N"); }
/// <summary> /// Initializes a new instance of the <see cref="T:EasyCaching.HybridCache.HybridCachingProvider"/> class. /// </summary> /// <param name="name">Name.</param> /// <param name="optionsAccs">Options accs.</param> /// <param name="factory">Providers factory</param> /// <param name="bus">Bus.</param> /// <param name="loggerFactory">Logger factory.</param> public HybridCachingProvider( string name , HybridCachingOptions optionsAccs , IEasyCachingProviderFactory factory , IEasyCachingBus bus = null , ILoggerFactory loggerFactory = null ) { ArgumentCheck.NotNull(factory, nameof(factory)); this._name = name; this._options = optionsAccs; ArgumentCheck.NotNullOrWhiteSpace(_options.TopicName, nameof(_options.TopicName)); this._logger = loggerFactory?.CreateLogger <HybridCachingProvider>(); // Here use the order to distinguish traditional provider var local = factory.GetCachingProvider(_options.LocalCacheProviderName); if (local.IsDistributedCache) { throw new NotFoundCachingProviderException("Can not found any local caching providers."); } else { this._localCache = local; } // Here use the order to distinguish traditional provider var distributed = factory.GetCachingProvider(_options.DistributedCacheProviderName); if (!distributed.IsDistributedCache) { throw new NotFoundCachingProviderException("Can not found any distributed caching providers."); } else { this._distributedCache = distributed; } this._bus = bus ?? NullEasyCachingBus.Instance; this._bus.Subscribe(_options.TopicName, OnMessage); this._cacheId = Guid.NewGuid().ToString("N"); // policy retryAsyncPolicy = Policy.Handle <Exception>() .WaitAndRetryAsync(this._options.BusRetryCount, retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt - 1))); retryPolicy = Policy.Handle <Exception>() .WaitAndRetry(this._options.BusRetryCount, retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt - 1))); fallbackPolicy = Policy.Handle <Exception>().Fallback(() => { }); fallbackAsyncPolicy = Policy.Handle <Exception>().FallbackAsync(ct => { return(Task.CompletedTask); }); _busSyncWrap = Policy.Wrap(fallbackPolicy, retryPolicy); _busAsyncWrap = Policy.WrapAsync(fallbackAsyncPolicy, retryAsyncPolicy); }