public MediumStore(ILoggerFactory loggerFactory, ProxyOptions proxyOptions) { _loggerFactory = loggerFactory; if (_loggerFactory == null) { throw new ArgumentNullException(nameof(loggerFactory)); } _logger = loggerFactory.CreateLogger <MediumStore>(); _proxyOptions = proxyOptions ?? new ProxyOptions(); }
public MediumCache(ILoggerFactory loggerFactory, ProxyOptions proxyOptions) { _logger = loggerFactory.CreateLogger <MediumCache>(); _proxyOptions = proxyOptions ?? new ProxyOptions(); _contents = new List <Item>(); RefreshCachePredicate = currentDateTime => { var targetDt = ModifiedDateTimeUtc.Add(_proxyOptions.CachePolicy.CacheLifecycleTimeSpan); _logger.LogInformation($"calling delegate RefreshCachePredicate(),{targetDt},{currentDateTime}"); return(targetDt < currentDateTime); }; RefreshCacheSpeculativeExecutionPredicate = currentDateTime => { var targetDt = ModifiedDateTimeUtc.Add( new TimeSpan((long)( _proxyOptions.CachePolicy.CacheLifecycleTimeSpan.Ticks * _proxyOptions.CachePolicy.CacheLifecycleSpeculativeExecutionRate))); _logger.LogInformation($"calling delegate RefreshCacheSpeculativeExecutionPredicate(),{targetDt},{currentDateTime}"); return(targetDt < currentDateTime); }; ModifiedDateTimeUtc = DateTime.MinValue; // monitoring thread. Task.Factory.StartNew(async() => { while (_executeMonitoringThread) { await Task.Delay(_proxyOptions.CachePolicy.MonitoringThreadInterval); _logger.LogInformation($"calling ()monitoring. _executeMonitoringThread={ _executeMonitoringThread},interval={_proxyOptions.CachePolicy.MonitoringThreadInterval}"); if (RefreshCacheSpeculativeExecutionPredicate(DateTime.UtcNow)) { await RefreshCacheAsync(true); } } }).ConfigureAwait(false); }