public DefaultLiteDBCachingProvider(
            string name,
            IEnumerable <ILiteDBDatabaseProvider> dbProviders,
            LiteDBOptions options,
            ILoggerFactory loggerFactory = null)
        {
            this._dbProvider = dbProviders.Single(x => x.DBProviderName.Equals(name));
            this._options    = options;
            this._logger     = loggerFactory?.CreateLogger <DefaultLiteDBCachingProvider>();
            this._litedb     = _dbProvider.GetConnection();
            this._cache      = _litedb.GetCollection <CacheItem>(name);
            this._cacheStats = new CacheStats();
            this._name       = name;

            this.ProviderName          = this._name;
            this.ProviderType          = CachingProviderType.LiteDB;
            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
            };

            InitDb();
        }
Beispiel #2
0
        public LiteDBCachingTest()
        {
            IServiceCollection services = new ServiceCollection();

            services.AddEasyCaching(x =>
                                    x.UseLiteDB(options =>
            {
                options.DBConfig = new  LiteDBDBOptions
                {
                    FileName = "s1.ldb"
                };
            })
                                    );

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

            _dbProvider = _dbProviders.FirstOrDefault();


            _provider = new DefaultLiteDBCachingProvider(EasyCachingConstValue.DefaultLiteDBName, _dbProviders,
                                                         new LiteDBOptions());
            _defaultTs = TimeSpan.FromSeconds(30);
        }