public NodeTracker(CacheSettings settings) { _nowProvider = settings.NowProvider; _observers = new CacheValueObservable <TValue>(); var maxAgeInMilliseconds = Math.Min(settings.MaxAge.TotalMilliseconds, MaxAgeUpperLimit); _minAge = settings.MinAge; _maxAge = TimeSpan.FromMilliseconds(maxAgeInMilliseconds); _validityCheckInterval = TimeSpan.FromMilliseconds(maxAgeInMilliseconds / settings.TimeSlots); _cacheResetTime = _nowProvider().Add(TimeSpan.FromMilliseconds(MaxAgeUpperLimit)); _bucketSize = Math.Max(settings.Capacity / settings.BucketCount, 1); // enough buckets for all of the content within the time slices, plus a few spares _bucketCount = settings.TimeSlots * settings.BucketCount + 5; _buckets = new BucketCollection <TValue>(this, _bucketCount); Statistics = new CacheStatistics(settings.Capacity, _bucketCount, _bucketSize, _minAge, _maxAge, _validityCheckInterval); OpenBucket(0); }
public NodeTracker(int capacity, TimeSpan minAge, TimeSpan maxAge, CurrentTimeProvider nowProvider) { _nowProvider = nowProvider; _observers = new CacheValueObservable <TValue>(); var maxAgeInMilliseconds = Math.Min(maxAge.TotalMilliseconds, MaxAgeUpperLimit); _minAge = minAge; _maxAge = TimeSpan.FromMilliseconds(maxAgeInMilliseconds); _validityCheckInterval = TimeSpan.FromMilliseconds(maxAgeInMilliseconds / 240.0); _cacheResetTime = nowProvider().Add(TimeSpan.FromMilliseconds(MaxAgeUpperLimit)); var capacityBucketCount = 20; _bucketSize = Math.Max(capacity / capacityBucketCount, 1); _bucketCount = 240 * capacityBucketCount + 5; _buckets = new BucketCollection <TValue>(this, _bucketCount); Statistics = new CacheStatistics(capacity, _bucketCount, _bucketSize, minAge, maxAge, _validityCheckInterval); OpenBucket(0); }
/// <summary> /// Enable the code feature between the specified dates /// </summary> /// <typeparam name="T"></typeparam> /// <param name="factory"></param> /// <param name="startDateTime"></param> /// <param name="endDateTime"></param> /// <param name="currentTimeProvider"></param> /// <returns></returns> public static IToggleCodeSwitch <T> EnableBetween <T>(this ICodeSwitchFactory factory, DateTime startDateTime, DateTime endDateTime, CurrentTimeProvider currentTimeProvider = null) where T : struct, ICodeFeature { return(new DateRangeCodeSwitch <T>(true, startDateTime, endDateTime, currentTimeProvider ?? DefaultTimeProvider)); }
public MainViewModel() { _count = CurrentTimeProvider.GetCurrentCounter(); _time = CurrentTimeProvider.Period - CurrentTimeProvider.GetCurrentTime(); ConfigurationStorage.Section.Items.OfType <AuthenticationItem>().ToList().ForEach(i => _items.Add(new ItemViewModel(i))); _items.ToList().ForEach(i => i.UpdateCode(_count)); _timer = new Timer(DoOnEachTimerTick, null, TimeSpan.FromMilliseconds(50), TimeSpan.FromMilliseconds(50)); }
public DateRangeCodeSwitch(bool switchEnabled, DateTime?enabledFrom, DateTime?enabledTo, CurrentTimeProvider currentTimeProvider) { _switchEnabled = switchEnabled; _enabledFrom = enabledFrom; _enabledTo = enabledTo; _currentTimeProvider = currentTimeProvider; _evaluated = new CodeSwitchEvaluatedObservable <TFeature>(); _enabled = new Lazy <bool>(Evaluate); }
private void DoOnEachTimerTick(object state) { try { Dispatcher.CurrentDispatcher.Invoke(() => { Time = CurrentTimeProvider.Period - CurrentTimeProvider.GetCurrentTime(); var count = CurrentTimeProvider.GetCurrentCounter(); if (_count != count) { _count = count; _items.ToList().ForEach(i => i.UpdateCode(_count)); } }); } catch { } }
public CacheSettings(int capacity = 10000, TimeSpan?minAge = default, TimeSpan?maxAge = default, CurrentTimeProvider nowProvider = default) { Capacity = capacity; MinAge = minAge ?? TimeSpan.FromMinutes(1); MaxAge = maxAge ?? TimeSpan.FromHours(24); NowProvider = nowProvider ?? CurrentTime; BucketCount = 20; TimeSlots = 240; }
public GenericMessageQueue() { this.timeProvider = Activator.CreateInstance(typeof(TP)) as CurrentTimeProvider; }
public MultiGranularityPercentileCounter(TimeSpan expiryInterval, TimeSpan granularityInterval, MultiGranularityPercentileCounter.Param[] parameters, CurrentTimeProvider currentTimeProvider) { this.count = parameters.Length; ExAssert.RetailAssert(this.count > 0, "Number of parameters: {0} must be greater than zero.", new object[] { this.count }); for (int i = 0; i < this.count - 1; i++) { ExAssert.RetailAssert(parameters[i].Granularity < parameters[i + 1].Granularity, "The granularities must be sorted."); ExAssert.RetailAssert(parameters[i].Range < parameters[i + 1].Range, "The ranges must be sorted."); ExAssert.RetailAssert(parameters[i].Range % parameters[i + 1].Granularity == 0L, "The range[i] MOD granularity[i + 1] must be zero."); } this.percentileCounters = new PercentileCounter[this.count]; this.borderBuckets = new long[this.count]; for (int j = 0; j < this.count; j++) { this.percentileCounters[j] = new PercentileCounter(expiryInterval, granularityInterval, parameters[j].Granularity, parameters[j].Range, currentTimeProvider); this.borderBuckets[j] = parameters[j].Range - parameters[j].Granularity; } }
public PercentileCounter(TimeSpan expiryInterval, TimeSpan granularityInterval, long valueGranularity, long valueMaximum, CurrentTimeProvider currentTimeProvider) { if (granularityInterval <= TimeSpan.Zero) { throw new ArgumentOutOfRangeException(string.Format(CultureInfo.InvariantCulture, "granularityInterval: [{0}] must be greater than zero.", new object[] { granularityInterval })); } if (expiryInterval <= TimeSpan.Zero) { throw new ArgumentOutOfRangeException(string.Format(CultureInfo.InvariantCulture, "expiryInterval: [{0}] must be greater than zero.", new object[] { expiryInterval })); } if (expiryInterval != TimeSpan.MaxValue && granularityInterval >= expiryInterval) { throw new ArgumentOutOfRangeException(string.Format(CultureInfo.InvariantCulture, "granularityInterval: [{0}] must be less than or equal to expiryInterval: [{1}]", new object[] { granularityInterval, expiryInterval })); } if (valueGranularity <= 0L) { throw new ArgumentOutOfRangeException(string.Format(CultureInfo.InvariantCulture, "valueGranularity: [{0}] must be greater than 0.", new object[] { valueGranularity })); } if (valueMaximum <= 0L) { throw new ArgumentOutOfRangeException(string.Format(CultureInfo.InvariantCulture, "valueMaximum: [{0}] must be greater than 0.", new object[] { valueMaximum })); } if (valueGranularity >= valueMaximum) { throw new ArgumentOutOfRangeException(string.Format(CultureInfo.InvariantCulture, "valueGranularity: [{0}] must be less than valueMaximum: [{1}]", new object[] { valueGranularity, valueMaximum })); } this.granularityInterval = granularityInterval; this.expiryInterval = expiryInterval; if (currentTimeProvider != null) { this.currentTimeProvider = currentTimeProvider; } else { this.currentTimeProvider = new CurrentTimeProvider(this.CurrentTime); } this.creationTime = this.currentTimeProvider(); this.mainSummary = new PercentileCounter.PercentileCounterSummary(valueGranularity, valueMaximum); if (this.expiryInterval != TimeSpan.MaxValue) { int num = (int)((this.expiryInterval.Ticks + this.granularityInterval.Ticks - 1L) / this.granularityInterval.Ticks); this.summaryBuckets = new PercentileCounter.PercentileCounterSummary[num]; for (int i = 0; i < num; i++) { this.summaryBuckets[i] = new PercentileCounter.PercentileCounterSummary(valueGranularity, valueMaximum); } } }
/// <summary> /// Enable the code feature until the specified date/time /// </summary> /// <typeparam name="T"></typeparam> /// <param name="factory"></param> /// <param name="dateTime"></param> /// <param name="currentTimeProvider"></param> /// <returns></returns> public static IToggleCodeSwitch <T> EnableUntil <T>(this ICodeSwitchFactory factory, DateTime dateTime, CurrentTimeProvider currentTimeProvider = null) where T : struct, ICodeFeature { return(new DateRangeCodeSwitch <T>(true, null, dateTime, currentTimeProvider ?? DefaultTimeProvider)); }
/// <summary> /// /// </summary> /// <param name="capacity">The typical maximum capacity of the cache (not a hard limit)</param> /// <param name="minAge">The minmum time an item is cached before being eligible for removal</param> /// <param name="maxAge">The maximum time an unaccessed item will remain in the cache</param> /// <param name="nowProvider">Provides the current time</param> public GreenCache(int capacity, TimeSpan minAge, TimeSpan maxAge, CurrentTimeProvider nowProvider) { _indices = new Dictionary <string, ICacheIndex <TValue> >(); _nodeTracker = new NodeTracker <TValue>(capacity, minAge, maxAge, nowProvider); }
public GenericMessageQueue(CurrentTimeProvider timeProvider) { this.timeProvider = timeProvider; }