示例#1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="T:EasyCaching.InMemory.DefaultInMemoryCachingProvider"/> class.
        /// </summary>
        /// <param name="name">Name.</param>
        /// <param name="cache">Cache.</param>
        /// <param name="options">Options.</param>
        /// <param name="factory">Distributed lock factory</param>
        /// <param name="loggerFactory">Logger factory.</param>
        public DefaultInMemoryCachingProvider(
            string name,
            IEnumerable <IInMemoryCaching> cache,
            InMemoryOptions options,
            IDistributedLockFactory factory = null,
            ILoggerFactory loggerFactory    = null)
            : base(factory, options)
        {
            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.ProviderType          = CachingProviderType.InMemory;
            this.ProviderStats         = _cacheStats;
            this.ProviderMaxRdSecond   = _options.MaxRdSecond;
            this.IsDistributedProvider = false;

            _info = new ProviderInfo
            {
                CacheStats            = _cacheStats,
                EnableLogging         = options.EnableLogging,
                IsDistributedProvider = IsDistributedProvider,
                LockMs         = options.LockMs,
                MaxRdSecond    = options.MaxRdSecond,
                ProviderName   = ProviderName,
                ProviderType   = ProviderType,
                SerializerName = options.SerializerName,
                SleepMs        = options.SleepMs,
                CacheNulls     = options.CacheNulls,
            };
        }
示例#2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="T:EasyCaching.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, cache, options, null, loggerFactory)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="T:EasyCaching.Memory.MemoryCachingProvider"/> class.
 /// </summary>
 /// <param name="cache">Microsoft MemoryCache.</param>
 public DefaultInMemoryCachingProvider(
     IMemoryCache cache,
     InMemoryOptions options)
 {
     this._cache     = cache;
     this._options   = options;
     this._cacheKeys = new ConcurrentCollections.ConcurrentHashSet <string>();
 }
示例#4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="T:EasyCaching.Memory.MemoryCachingProvider"/> class.
 /// </summary>
 /// <param name="cache">Microsoft MemoryCache.</param>
 public DefaultInMemoryCachingProvider(
     IMemoryCache cache,
     InMemoryOptions options,
     ILoggerFactory loggerFactory = null)
 {
     this._cache     = cache;
     this._options   = options;
     this._logger    = loggerFactory?.CreateLogger <DefaultInMemoryCachingProvider>();
     this._cacheKeys = new ConcurrentCollections.ConcurrentHashSet <string>();
 }
示例#5
0
        /// <summary>
        /// Adds the default in-memory cache.
        /// </summary>
        /// <returns>The default in-memory cache.</returns>
        /// <param name="services">Services.</param>
        public static IServiceCollection AddDefaultInMemoryCache(this IServiceCollection services)
        {
            var option = new InMemoryOptions();

            return(services.AddDefaultInMemoryCache(x =>
            {
                x.CachingProviderType = option.CachingProviderType;
                x.MaxRdSecond = option.MaxRdSecond;
                x.Order = option.Order;
            }));
        }
示例#6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="T:EasyCaching.InMemory.DefaultInMemoryCachingProvider"/> class.
        /// </summary>
        /// <param name="cache">Cache.</param>
        /// <param name="options">Options.</param>
        /// <param name="loggerFactory">Logger factory.</param>
        public DefaultInMemoryCachingProvider(
            IInMemoryCaching cache,
            IOptionsMonitor <InMemoryOptions> options,
            ILoggerFactory loggerFactory = null)
        {
            this._cache   = cache;
            this._options = options.CurrentValue;
            this._logger  = loggerFactory?.CreateLogger <DefaultInMemoryCachingProvider>();
            //this._cacheKeys = new ConcurrentCollections.ConcurrentHashSet<string>();

            this._cacheStats = new CacheStats();
            //this._name = EasyCachingConstValue.DefaultInMemoryName;
        }
        /// <summary>
        /// Uses the in memory.
        /// </summary>
        /// <returns>The in memory.</returns>
        /// <param name="options">Options.</param>
        /// <param name="name">Name.</param>
        public static EasyCachingOptions UseInMemory(this EasyCachingOptions options, string name = EasyCachingConstValue.DefaultInMemoryName)
        {
            var option = new InMemoryOptions();

            void configure(InMemoryOptions x)
            {
                x.EnableLogging = option.EnableLogging;
                x.MaxRdSecond   = option.MaxRdSecond;
                x.DBConfig      = option.DBConfig;
            }

            return(options.UseInMemory(configure, name));
        }
示例#8
0
        /// <summary>
        /// Adds the default in-memory cache.
        /// </summary>
        /// <returns>The default in-memory cache.</returns>
        /// <param name="services">Services.</param>
        public static IServiceCollection AddDefaultInMemoryCacheWithFactory(
            this IServiceCollection services,
            string providerName = EasyCachingConstValue.DefaultInMemoryName)
        {
            ArgumentCheck.NotNullOrWhiteSpace(providerName, nameof(providerName));

            var option = new InMemoryOptions();

            return(services.AddDefaultInMemoryCacheWithFactory(providerName, x =>
            {
                x.CachingProviderType = option.CachingProviderType;
                x.MaxRdSecond = option.MaxRdSecond;
                x.Order = option.Order;
            }));
        }
示例#9
0
        /// <summary>
        /// Uses the in memory.
        /// </summary>
        /// <returns>The in memory.</returns>
        /// <param name="options">Options.</param>
        /// <param name="name">Name.</param>
        public static EasyCachingOptions UseInMemory(this EasyCachingOptions options, string name = "")
        {
            var option = new InMemoryOptions();

            void configure(InMemoryOptions x)
            {
                x.CachingProviderType = option.CachingProviderType;
                x.EnableLogging       = option.EnableLogging;
                x.MaxRdSecond         = option.MaxRdSecond;
                x.Order = option.Order;
            }

            options.RegisterExtension(new InMemoryOptionsExtension(name, configure));

            return(options);
        }
        /// <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 EasyCachingOptions UseInMemory(this EasyCachingOptions options, IConfiguration configuration, string name = EasyCachingConstValue.DefaultInMemoryName, string sectionName = EasyCachingConstValue.InMemorySection)
        {
            var dbConfig      = configuration.GetSection(sectionName);
            var memoryOptions = new InMemoryOptions();

            dbConfig.Bind(memoryOptions);

            void configure(InMemoryOptions x)
            {
                x.EnableLogging = memoryOptions.EnableLogging;
                x.MaxRdSecond   = memoryOptions.MaxRdSecond;
                x.DBConfig      = memoryOptions.DBConfig;
            }

            return(options.UseInMemory(configure, name));
        }
示例#11
0
        /// <summary>
        /// Adds the default in-memory cache.
        /// </summary>
        /// <returns>The default in-memory cache.</returns>
        /// <param name="services">Services.</param>
        /// <param name="optionSetup">Option setup.</param>
        public static IServiceCollection AddDefaultInMemoryCache(
            this IServiceCollection services,
            Action <InMemoryOptions> optionSetup)
        {
            ArgumentCheck.NotNull(services, nameof(services));
            ArgumentCheck.NotNull(optionSetup, nameof(optionSetup));

            var option = new InMemoryOptions();

            optionSetup(option);
            services.AddSingleton(option);

            services.AddMemoryCache();
            services.TryAddSingleton <IEasyCachingProvider, DefaultInMemoryCachingProvider>();

            return(services);
        }
示例#12
0
        /// <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>
        public static EasyCachingOptions UseInMemory(this EasyCachingOptions options, IConfiguration configuration, string name = "")
        {
            var dbConfig      = configuration.GetSection(EasyCachingConstValue.InMemorySection);
            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;
            }

            options.RegisterExtension(new InMemoryOptionsExtension(name, configure));

            return(options);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="T:EasyCaching.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.ProviderType          = CachingProviderType.InMemory;
            this.ProviderStats         = _cacheStats;
            this.ProviderMaxRdSecond   = _options.MaxRdSecond;
            this.IsDistributedProvider = false;
        }
示例#14
0
        /// <summary>
        /// Initializes a new instance of the <see cref="T:EasyCaching.InMemory.DefaultInMemoryCachingProvider"/> class.
        /// </summary>
        /// <param name="cache">Cache.</param>
        /// <param name="options">Options.</param>
        /// <param name="loggerFactory">Logger factory.</param>
        public DefaultInMemoryCachingProvider(
            IInMemoryCaching cache,
            IOptionsMonitor <InMemoryOptions> options,
            ILoggerFactory loggerFactory = null)
        {
            this._cache   = cache;
            this._options = options.CurrentValue;
            this._logger  = loggerFactory?.CreateLogger <DefaultInMemoryCachingProvider>();

            this._cacheStats = new CacheStats();
            //this._name = EasyCachingConstValue.DefaultInMemoryName;

            this.ProviderName          = _name;
            this.ProviderStats         = _cacheStats;
            this.ProviderType          = _options.CachingProviderType;
            this.ProviderMaxRdSecond   = _options.MaxRdSecond;
            this.ProviderOrder         = _options.Order;
            this.IsDistributedProvider = false;
        }