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);
        }
        public SQLiteCachingTest()
        {
            IServiceCollection services = new ServiceCollection();

            services.AddSQLiteCache(options =>
            {
                options.FileName  = "";
                options.FilePath  = "";
                options.CacheMode = Microsoft.Data.Sqlite.SqliteCacheMode.Default;
                options.OpenMode  = Microsoft.Data.Sqlite.SqliteOpenMode.Memory;
            });

            IServiceProvider serviceProvider = services.BuildServiceProvider();

            _dbProvider = serviceProvider.GetService <ISQLiteDatabaseProvider>();

            var conn = _dbProvider.GetConnection();

            if (conn.State == System.Data.ConnectionState.Closed)
            {
                conn.Open();
            }
            conn.Execute(ConstSQL.CREATESQL);

            _provider  = new DefaultSQLiteCachingProvider(_dbProvider, new OptionsWrapper <SQLiteOptions>(new SQLiteOptions()));
            _defaultTs = TimeSpan.FromSeconds(30);
        }
        public SQLiteCachingTest()
        {
            IServiceCollection services = new ServiceCollection();

            services.AddEasyCaching(x =>
                                    x.UseSQLite(options =>
            {
                options.DBConfig = new SQLiteDBOptions
                {
                    FileName  = "s1.db",
                    CacheMode = Microsoft.Data.Sqlite.SqliteCacheMode.Default,
                    OpenMode  = Microsoft.Data.Sqlite.SqliteOpenMode.Memory,
                };
            })
                                    );

            IServiceProvider serviceProvider = services.BuildServiceProvider();
            var _dbProviders = serviceProvider.GetServices <ISQLiteDatabaseProvider>();

            _dbProvider = _dbProviders.FirstOrDefault();

            var conn = _dbProvider.GetConnection();

            if (conn.State == System.Data.ConnectionState.Closed)
            {
                conn.Open();
            }

            conn.Execute(ConstSQL.CREATESQL);

            _provider = new DefaultSQLiteCachingProvider(EasyCachingConstValue.DefaultSQLiteName, _dbProviders,
                                                         new SQLiteOptions());
            _defaultTs = TimeSpan.FromSeconds(30);
        }
 /// <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();
 }
Exemple #5
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();
 }
        /// <summary>
        /// init database
        /// </summary>
        /// <param name="dbProvider"></param>
        private void InitDb(ISQLiteDatabaseProvider dbProvider)
        {
            var conn = dbProvider.GetConnection();

            if (conn.State == System.Data.ConnectionState.Closed)
            {
                conn.Open();
            }

            conn.Execute(ConstSQL.CREATESQL);
        }
Exemple #7
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();
 }
 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;
 }
        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;
        }
Exemple #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;
        }
Exemple #11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="T:EasyCaching.SQLite.SQLiteCachingProvider"/> class.
 /// </summary>
 /// <param name="dbProvider">dbProvider.</param>
 public SQLiteCachingProvider(ISQLiteDatabaseProvider dbProvider)
 {
     this._dbProvider = dbProvider;
     this._cache      = _dbProvider.GetConnection();
 }