예제 #1
0
파일: Cache.cs 프로젝트: zhuxuland/c-sharp
 /// <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
     });
 }
예제 #2
0
파일: Cache.cs 프로젝트: zhuxuland/c-sharp
 /// <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);
 }
예제 #3
0
파일: Cache.cs 프로젝트: zhuxuland/c-sharp
        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);
            }
        }
예제 #4
0
파일: Cache.cs 프로젝트: zhuxuland/c-sharp
 void IDeserializationCallback.OnDeserialization(object sender)
 {
     _Level1Cache = new Level1CacheClass <TKey>(((ObjectComparerClass <TKey>)_Level2Cache.Comparer)._KeyComparer);
 }