public ConstrainedCache(IEqualityComparer <K> keyComparer, SizeCalculationDelegate calculator, long maxBytes, TimeSpan usageWindow, TimeSpan minCleanupInterval) { EventCountingStrategy s = new EventCountingStrategy(); s.MaxBytesUsed = maxBytes; s.MinimumCleanupInterval = minCleanupInterval; s.CounterGranularity = 16; usage = new EventCountingDictionary <K>(keyComparer, usageWindow, s); usage.CounterRemoved += new EventCountingDictionary <K> .EventKeyRemoved(usage_CounterRemoved); data = new Dictionary <K, V>(keyComparer); this.calculator = calculator; }
public EventCountingDictionary(IEqualityComparer <T> keyComparer, TimeSpan trackingDuration, EventCountingStrategy strategy) { this._trackingDuration = trackingDuration; this.granularity = strategy.CounterGranularity; precision = strategy.Threading; keysToCounters = new Dictionary <T, EventCounter>(keyComparer); countersToKeys = new Dictionary <EventCounter, T>(); //Est size per item itemSize = strategy.EstimatedCounterSize; //Max bytes byteCeiling = strategy.MaxBytesUsed; cleanupInterval = strategy.MinimumCleanupInterval.Ticks; }