Example #1
0
 void usage_CounterRemoved(EventCountingDictionary <K> sender, K key, int value)
 {
     //May be exected inside usage.lockSync AND lockSync
     lock (lockSync) {
         data.Remove(key);
     }
 }
Example #2
0
        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;
        }