public DefaultSQLiteCachingProvider(
            string name,
            IEnumerable <ISQLiteDatabaseProvider> dbProviders,
            SQLiteOptions options,
            ILoggerFactory loggerFactory = null)
        {
            this._dbProvider = dbProviders.Single(x => x.DBProviderName.Equals(name));
            this._options    = options;
            this._logger     = loggerFactory?.CreateLogger <DefaultSQLiteCachingProvider>();
            this._cache      = _dbProvider.GetConnection();
            this._cacheStats = new CacheStats();
            this._name       = name;

            this.ProviderName          = this._name;
            this.ProviderType          = CachingProviderType.SQLite;
            this.ProviderStats         = this._cacheStats;
            this.ProviderMaxRdSecond   = _options.MaxRdSecond;
            this.IsDistributedProvider = true;

            _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
            };

            InitDb(_dbProvider);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="T:EasyCaching.SQLite.SQLiteCachingProvider"/> class.
 /// </summary>
 /// <param name="dbProvider">dbProvider.</param>
 public DefaultSQLiteCachingProvider(
     ISQLiteDatabaseProvider dbProvider,
     SQLiteOptions options)
 {
     this._dbProvider = dbProvider;
     this._options    = options;
     this._cache      = _dbProvider.GetConnection();
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="T:EasyCaching.SQLite.SQLiteCachingProvider"/> class.
 /// </summary>
 /// <param name="dbProvider">dbProvider.</param>
 public DefaultSQLiteCachingProvider(
     ISQLiteDatabaseProvider dbProvider,
     SQLiteOptions options,
     ILoggerFactory loggerFactory = null)
 {
     this._dbProvider = dbProvider;
     this._options    = options;
     this._logger     = loggerFactory?.CreateLogger <DefaultSQLiteCachingProvider>();
     this._cache      = _dbProvider.GetConnection();
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="T:EasyCaching.SQLite.SQLiteCachingProvider"/> class.
 /// </summary>
 /// <param name="dbProvider">dbProvider.</param>
 public DefaultSQLiteCachingProvider(
     ISQLiteDatabaseProvider dbProvider,
     IOptionsMonitor <SQLiteOptions> options,
     ILoggerFactory loggerFactory = null)
 {
     this._dbProvider = dbProvider;
     this._options    = options.CurrentValue;
     this._logger     = loggerFactory?.CreateLogger <DefaultSQLiteCachingProvider>();
     this._cache      = _dbProvider.GetConnection();
     this._cacheStats = new CacheStats();
 }
        /// <summary>
        /// Adds the SQLite cache.
        /// </summary>
        /// <returns>The SQLite cache.</returns>
        /// <param name="services">Services.</param>
        /// <param name="optionsAction">Options action.</param>
        public static IServiceCollection AddSQLiteCache(
            this IServiceCollection services,
            Action <SQLiteDBOption> optionsAction)
        {
            var providerOptions = new SQLiteOptions();

            return(services.AddSQLiteCache(optionsAction, x =>
            {
                x.CachingProviderType = providerOptions.CachingProviderType;
                x.MaxRdSecond = providerOptions.MaxRdSecond;
                x.Order = providerOptions.Order;
            }));
        }
 public DefaultSQLiteCachingProvider(
     string name,
     IEnumerable <ISQLiteDatabaseProvider> dbProviders,
     SQLiteOptions options,
     ILoggerFactory loggerFactory = null)
 {
     this._dbProvider = dbProviders.FirstOrDefault(x => x.DBProviderName.Equals(name));
     this._options    = options;
     this._logger     = loggerFactory?.CreateLogger <DefaultSQLiteCachingProvider>();
     this._cache      = _dbProvider.GetConnection();
     this._cacheStats = new CacheStats();
     this._name       = name;
 }
Ejemplo n.º 7
0
        public SQLiteDatabaseProvider(string name, SQLiteOptions options)
        {
            _name    = name;
            _options = options.DBConfig;
            _builder = new SqliteConnectionStringBuilder
            {
                DataSource = _options.DataSource,
                Mode       = _options.OpenMode,
                Cache      = _options.CacheMode
            };

            _conns = new ConcurrentDictionary <int, SqliteConnection>();
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Uses the SQLite.
        /// </summary>
        /// <returns>The SQL ite.</returns>
        /// <param name="options">Options.</param>
        /// <param name="configuration">Configuration.</param>
        /// <param name="name">Name.</param>
        /// <param name="sectionName">Section name.</param>
        public static EasyCachingOptions UseSQLite(this EasyCachingOptions options, IConfiguration configuration, string name = EasyCachingConstValue.DefaultSQLiteName, string sectionName = EasyCachingConstValue.SQLiteSection)
        {
            var dbConfig = configuration.GetSection(sectionName);
            var sqliteOptions = new SQLiteOptions();
            dbConfig.Bind(sqliteOptions);

            void configure(SQLiteOptions x)
            {
                x.EnableLogging = sqliteOptions.EnableLogging;
                x.MaxRdSecond = sqliteOptions.MaxRdSecond;             
                x.DBConfig = sqliteOptions.DBConfig;
            }

            options.RegisterExtension(new SQLiteOptionsExtension(name, configure));
            return options;
        }
        public DefaultSQLiteCachingProvider(
            string name,
            IEnumerable <ISQLiteDatabaseProvider> dbProviders,
            SQLiteOptions options,
            ILoggerFactory loggerFactory = null)
        {
            this._dbProvider = dbProviders.Single(x => x.DBProviderName.Equals(name));
            this._options    = options;
            this._logger     = loggerFactory?.CreateLogger <DefaultSQLiteCachingProvider>();
            this._cache      = _dbProvider.GetConnection();
            this._cacheStats = new CacheStats();
            this._name       = name;

            this.ProviderName          = this._name;
            this.ProviderType          = CachingProviderType.SQLite;
            this.ProviderStats         = this._cacheStats;
            this.ProviderMaxRdSecond   = _options.MaxRdSecond;
            this.IsDistributedProvider = true;
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="T:EasyCaching.SQLite.SQLiteCachingProvider"/> class.
        /// </summary>
        /// <param name="dbProvider">dbProvider.</param>
        public DefaultSQLiteCachingProvider(
            ISQLiteDatabaseProvider dbProvider,
            IOptionsMonitor <SQLiteOptions> options,
            ILoggerFactory loggerFactory = null)
        {
            this._dbProvider = dbProvider;
            this._options    = options.CurrentValue;
            this._logger     = loggerFactory?.CreateLogger <DefaultSQLiteCachingProvider>();
            this._cache      = _dbProvider.GetConnection();
            this._cacheStats = new CacheStats();
            this._name       = EasyCachingConstValue.DefaultSQLiteName;

            this.ProviderName          = this._name;
            this.ProviderStats         = this._cacheStats;
            this.ProviderType          = _options.CachingProviderType;
            this.ProviderOrder         = _options.Order;
            this.ProviderMaxRdSecond   = _options.MaxRdSecond;
            this.IsDistributedProvider = false;
        }
        /// <summary>
        /// Adds the SQLite cache.
        /// </summary>
        /// <returns>The SQLite cache.</returns>
        /// <param name="services">Services.</param>
        /// <param name="dbAction">Db action.</param>
        /// <param name="providerAction">Provider action.</param>
        public static IServiceCollection AddSQLiteCache(
            this IServiceCollection services,
            Action <SQLiteDBOption> dbAction,
            Action <SQLiteOptions> providerAction)
        {
            ArgumentCheck.NotNull(services, nameof(services));
            ArgumentCheck.NotNull(dbAction, nameof(dbAction));

            services.AddOptions();
            services.Configure(dbAction);

            var providerOptions = new SQLiteOptions();

            providerAction(providerOptions);
            services.AddSingleton(providerOptions);

            services.TryAddSingleton <ISQLiteDatabaseProvider, SQLiteDatabaseProvider>();
            services.TryAddSingleton <IEasyCachingProvider, DefaultSQLiteCachingProvider>();

            return(services);
        }
Ejemplo n.º 12
0
 public SQLiteDatabaseProvider(string name, SQLiteOptions options)
 {
     this._name    = name;
     this._options = options.DBConfig;
 }