Beispiel #1
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);
        }
Beispiel #2
0
        public void Clear()
        {
            lock (_lock)
            {
                _buckets.Empty();

                _buckets = new BucketCollection <TValue>(this, _bucketCount);

                _cacheResetTime = _nowProvider().Add(TimeSpan.FromMilliseconds(MaxAgeUpperLimit));

                OldestBucketIndex = 0;

                OpenBucket(0);

                Statistics.Reset();

                _observers.CacheCleared();
            }
        }