コード例 #1
0
        public SqliteCache(SqliteCacheOptions options, ILogger <SqliteCache>?logger = null)
        {
            _config = options;
            _logger = logger ?? new NullLogger <SqliteCache>();

            // Silence warnings about variables not initialized in constructor because they ARE
            // initialized in the call to `Connect()`.
            _db      = null !;
            Commands = null !;
            Connect();

            // Directly checking _db/Commands will cause Roslyn to think they may be null
            var x = _db;

            Debug.Assert(x != null);
            var y = Commands;

            Debug.Assert(y != null);

            // This has to be after the call to Connect()
            if (_config.CleanupInterval.HasValue)
            {
                _cleanupTimer = new Timer(_ =>
                {
                    _logger.LogTrace("Beginning background cache cleanup");
                    RemoveExpired();
                    _logger.LogTrace("Completed background cache cleanup");
                }, null, TimeSpan.Zero, _config.CleanupInterval.Value);
            }
        }
コード例 #2
0
        public SqliteCache(SqliteCacheOptions options, ILogger <SqliteCache> logger)
        {
            _config = options;
            _logger = logger;

            Connect();

            // This has to be after the call to Connect()
            if (_config.CleanupInterval.HasValue)
            {
                _cleanupTimer = new Timer(_ =>
                {
                    _logger.LogTrace("Beginning background cache cleanup");
                    RemoveExpired();
                }, null, TimeSpan.Zero, _config.CleanupInterval.Value);
            }
        }