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