/// <summary> /// Creates a new <see cref="FusionCache"/> instance. /// </summary> /// <param name="optionsAccessor">The set of cache-wide options to use with this instance of <see cref="FusionCache"/>.</param> /// <param name="memoryCache">The <see cref="IMemoryCache"/> instance to use. If null, one will be automatically created and managed.</param> /// <param name="logger">The <see cref="ILogger{TCategoryName}"/> instance to use. If null, logging will be completely disabled.</param> /// <param name="reactor">The <see cref="IFusionCacheReactor"/> instance to use (advanced). If null, a standard one will be automatically created and managed.</param> public FusionCache(IOptions <FusionCacheOptions> optionsAccessor, IMemoryCache?memoryCache = null, ILogger <FusionCache>?logger = null, IFusionCacheReactor?reactor = null) { if (optionsAccessor is null) { throw new ArgumentNullException(nameof(optionsAccessor)); } // OPTIONS _options = optionsAccessor.Value ?? throw new ArgumentNullException(nameof(optionsAccessor.Value)); // LOGGING if (logger is NullLogger <FusionCache> ) { // IGNORE NULL LOGGER (FOR BETTER PERF) _logger = null; } else { _logger = logger; } // REACTOR _reactor = reactor ?? new FusionCacheReactorStandard(); // MEMORY CACHE _mca = new MemoryCacheAccessor(memoryCache, _options, _logger); // DISTRIBUTED CACHE _dca = null; }
/// <summary> /// Release all resources managed by FusionCache. /// </summary> /// <param name="disposing">Indicates if the disposing is happening.</param> protected virtual void Dispose(bool disposing) { if (!disposedValue) { if (disposing) { _reactor.Dispose(); _mca.Dispose(); } #pragma warning disable CS8625 // Cannot convert null literal to non-nullable reference type. _mca = null; #pragma warning restore CS8625 // Cannot convert null literal to non-nullable reference type. disposedValue = true; } }