Ejemplo n.º 1
0
        public TValue Get(TKey key, MissingValueProvider <TKey, TValue> missingValueProvider)
        {
            _lock.EnterUpgradeableReadLock();
            try
            {
                if (_cache.Has(key))
                {
                    return(_cache.Get(key, missingValueProvider));
                }

                _lock.EnterWriteLock();
                try
                {
                    return(_cache.Get(key, missingValueProvider));
                }
                finally
                {
                    _lock.ExitWriteLock();
                }
            }
            finally
            {
                _lock.ExitUpgradeableReadLock();
            }
        }
Ejemplo n.º 2
0
 public ConcurrentCache(IDictionary <TKey, TValue> values,
                        IEqualityComparer <TKey> equalityComparer,
                        MissingValueProvider <TKey, TValue> missingValueProvider)
     : this(values, equalityComparer)
 {
     _missingValueProvider = missingValueProvider;
 }
Ejemplo n.º 3
0
 public QwConcurrent(IEnumerable <KeyValuePair <TKey, TValue> > values,
                     IEqualityComparer <TKey> equalityComparer,
                     MissingValueProvider <TKey, TValue> missingValueProvider)
     : this(values, equalityComparer)
 {
     _missingValueProvider = missingValueProvider;
 }
Ejemplo n.º 4
0
 public DictionaryCache(IDictionary <TKey, TValue> values,
                        MissingValueProvider <TKey, TValue> missingValueProvider,
                        bool copy)
     : this(values, copy)
 {
     _missingValueProvider = missingValueProvider;
 }
Ejemplo n.º 5
0
        public InterfaceReflectionCache()
        {
            _cache = new ConcurrentCache <Type, ICache <Type, Type> >(typeKey =>
            {
                MissingValueProvider <Type, Type> missingValueProvider = x => GetInterfaceInternal(typeKey, x);

                return(new ConcurrentCache <Type, Type>(missingValueProvider));
            });
        }
Ejemplo n.º 6
0
        public TValue Get(TKey key, MissingValueProvider <TKey, TValue> missingValueProvider)
        {
            TValue value;

            if (_values.TryGetValue(key, out value))
            {
                return(value);
            }

            value = missingValueProvider(key);

            Add(key, value);

            return(value);
        }
Ejemplo n.º 7
0
        public TValue Get(TKey key, MissingValueProvider <TKey, TValue> missingValueProvider)
        {
            bool added = false;

            TValue value = _values.GetOrAdd(key, x =>
            {
                added = true;
                return(missingValueProvider(x));
            });

            if (added)
            {
                _valueAddedCallback(key, value);
            }

            return(value);
        }
Ejemplo n.º 8
0
 public ConcurrentCache(IDictionary <TKey, TValue> values,
                        MissingValueProvider <TKey, TValue> missingValueProvider)
     : this(values)
 {
     _missingValueProvider = missingValueProvider;
 }
Ejemplo n.º 9
0
 public ConcurrentCache(IEqualityComparer <TKey> equalityComparer,
                        MissingValueProvider <TKey, TValue> missingValueProvider)
     : this(equalityComparer)
 {
     _missingValueProvider = missingValueProvider;
 }
Ejemplo n.º 10
0
 public ConcurrentCache(MissingValueProvider <TKey, TValue> missingValueProvider)
     : this()
 {
     _missingValueProvider = missingValueProvider;
 }
Ejemplo n.º 11
0
 public DictionaryCache(IDictionary <TKey, TValue> values,
                        MissingValueProvider <TKey, TValue> missingValueProvider)
     : this(values, true)
 {
     _missingValueProvider = missingValueProvider;
 }
Ejemplo n.º 12
0
 public DictionaryCache(IEqualityComparer <TKey> equalityComparer,
                        MissingValueProvider <TKey, TValue> missingValueProvider)
     : this(equalityComparer)
 {
     _missingValueProvider = missingValueProvider;
 }
Ejemplo n.º 13
0
 public DictionaryCache(MissingValueProvider <TKey, TValue> missingValueProvider)
     : this()
 {
     _missingValueProvider = missingValueProvider;
 }
Ejemplo n.º 14
0
 public TInterface Get(Type key, MissingValueProvider <Type, TInterface> missingValueProvider)
 {
     return(_cache.Get(key, missingValueProvider));
 }
Ejemplo n.º 15
0
 public TValue Get(TKey key, MissingValueProvider <TKey, TValue> missingValueProvider)
 {
     return(_cache.Get(key, missingValueProvider));
 }
Ejemplo n.º 16
0
 /// <summary>
 /// Constructs a cache for the specified generic type.
 /// </summary>
 /// <param name="genericType">The generic type to close</param>
 /// <param name="missingValueProvider">The implementation provider, which must close the generic type with the passed type</param>
 public GenericTypeCache(Type genericType, MissingValueProvider <Type, TInterface> missingValueProvider)
     : this(genericType, new ConcurrentCache <Type, TInterface>(missingValueProvider))
 {
 }
Ejemplo n.º 17
0
 public QwConcurrent(IEnumerable <KeyValuePair <TKey, TValue> > values,
                     MissingValueProvider <TKey, TValue> missingValueProvider)
     : this(values)
 {
     _missingValueProvider = missingValueProvider;
 }