/// <summary> /// Initializes a new instance of the <see cref="T:caching.InMemory.DefaultInMemoryCachingProvider"/> class. /// </summary> /// <param name="name">Name.</param> /// <param name="cache">Cache.</param> /// <param name="options">Options.</param> /// <param name="loggerFactory">Logger factory.</param> public DefaultInMemoryCachingProvider( string name, IEnumerable <IInMemoryCaching> cache, InMemoryOptions options, ILoggerFactory loggerFactory = null) { this._name = name; this._cache = cache.Single(x => x.ProviderName == _name); this._options = options; this._logger = loggerFactory?.CreateLogger <DefaultInMemoryCachingProvider>(); this._cacheStats = new CacheStats(); this.ProviderName = _name; this.ProviderStats = _cacheStats; this.ProviderType = _options.CachingProviderType; this.ProviderMaxRdSecond = _options.MaxRdSecond; this.ProviderOrder = _options.Order; this.IsDistributedProvider = false; }
/// <summary> /// Uses the in memory. /// </summary> /// <returns>The in memory.</returns> /// <param name="options">Options.</param> /// <param name="configuration">Configuration.</param> /// <param name="name">Name.</param> /// <param name="sectionName">SectionName.</param> public static IServiceCollection AddMemoryServices(this IServiceCollection services, IConfiguration configuration, string name = CachingConstValue.DefaultInMemoryName, string sectionName = CachingConstValue.InMemorySection) { var dbConfig = configuration.GetSection(sectionName); var memoryOptions = new InMemoryOptions(); dbConfig.Bind(memoryOptions); //void configure(InMemoryOptions x) //{ // x.CachingProviderType = memoryOptions.CachingProviderType; // x.EnableLogging = memoryOptions.EnableLogging; // x.MaxRdSecond = memoryOptions.MaxRdSecond; // x.Order = memoryOptions.Order; // x.DBConfig = memoryOptions.DBConfig; //} return(AddMemoryServices(services, x => { x.CachingProviderType = memoryOptions.CachingProviderType; x.EnableLogging = memoryOptions.EnableLogging; x.MaxRdSecond = memoryOptions.MaxRdSecond; x.Order = memoryOptions.Order; x.DBConfig = memoryOptions.DBConfig; }, name)); }