Ejemplo n.º 1
0
 /// <summary>
 /// Constructs a new instance of <see cref="Cache{TKey,TValue}"/> using an explicit <see cref="IEqualityComparer{TKey}"/> of TKey to comparer keys.
 /// </summary>
 /// <param name="keyComparer">The <see cref="IEqualityComparer{TKey}"/> of TKey to compare keys with.</param>
 public Cache(IEqualityComparer <TKey> keyComparer)
 {
     _Level1Cache = new Level1CacheClass <TKey>(keyComparer);
     _Level2Cache = new ConcurrentWeakDictionary <object, object>(new ObjectComparerClass <TKey> {
         _KeyComparer = keyComparer
     });
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Constructs a new instance of <see cref="Cache{TKey,TValue}"/> using an explicit <see cref="IEqualityComparer{TKey}"/> of TKey to comparer keys.
 /// </summary>
 /// <param name="keyComparer">The <see cref="IEqualityComparer{TKey}"/> of TKey to compare keys with.</param>
 public Cache(IEqualityComparer <TKey> keyComparer)
 {
     _keyComparer = keyComparer;
     _Level1Cache = new Level1CacheClass <TKey>(keyComparer);
     _Level2Cache = new WeakDictionary <object, bool, object>(new ObjectComparerClass <TKey> {
         _KeyComparer = keyComparer
     }, EqualityComparer <bool> .Default);
 }
Ejemplo n.º 3
0
        Cache(SerializationInfo serializationInfo, StreamingContext streamingContext)
        {
            _keyComparer = (IEqualityComparer <TKey>)serializationInfo.GetValue("Comparer", typeof(IEqualityComparer <TKey>));
            _Level1Cache = new Level1CacheClass <TKey>(_keyComparer);
            _Level2Cache = new WeakDictionary <object, bool, object>(new ObjectComparerClass <TKey> {
                _KeyComparer = _keyComparer
            }, EqualityComparer <bool> .Default);

            foreach (var kvp in (IEnumerable <KeyValuePair <TKey, TValue> >)serializationInfo.GetValue("Items", typeof(List <KeyValuePair <TKey, TValue> >)))
            {
                this.GetOldest(kvp.Key, kvp.Value);
            }
        }
Ejemplo n.º 4
0
 void IDeserializationCallback.OnDeserialization(object sender)
 {
     _Level1Cache = new Level1CacheClass <TKey>(((ObjectComparerClass <TKey>)_Level2Cache.Comparer)._KeyComparer);
 }