예제 #1
0
 /// <summary>
 /// Initializes new instance of this type.
 /// </summary>
 /// <param name="maxSize"><see cref="MaxSize"/> property value.</param>
 /// <param name="keyExtractor"><see cref="ICache{TKey, TItem}.KeyExtractor"/> property value.</param>
 /// <param name="cacheConverter"><see cref="CacheConverter"/> property value.</param>
 /// <param name="chainedCache"><see cref="ChainedCache"/> property value.</param>
 public LruCache(long maxSize, Converter <TItem, TKey> keyExtractor,
                 Biconverter <TItem, TCached> cacheConverter, ICache <TKey, TItem> chainedCache)
 {
     if (maxSize <= 0)
     {
         ArgumentValidator.EnsureArgumentIsInRange(maxSize, 1, long.MaxValue, "maxSize");
     }
     ArgumentValidator.EnsureArgumentNotNull(keyExtractor, "keyExtractor");
     this.maxSize        = maxSize;
     this.KeyExtractor   = keyExtractor;
     this.cacheConverter = cacheConverter;
     this.chainedCache   = chainedCache;
     // deque = new TopDeque<TKey, TCached>(1 + (int) maxSize);
     deque = new TopDeque <TKey, TCached>();
 }
예제 #2
0
 /// <summary>
 /// Initializes new instance of this type.
 /// </summary>
 /// <param name="maxSize"><see cref="MaxSize"/> property value.</param>
 /// <param name="keyExtractor"><see cref="KeyExtractor"/> property value.</param>
 /// <param name="sizeExtractor"><see cref="SizeExtractor"/> property value.</param>
 /// <param name="chainedCache"><see cref="ChainedCache"/> property value.</param>
 public LruCache(long maxSize, Converter <TItem, TKey> keyExtractor,
                 Func <TItem, long> sizeExtractor, ICache <TKey, TItem> chainedCache)
 {
     if (maxSize <= 0)
     {
         ArgumentValidator.EnsureArgumentIsInRange(maxSize, 1, long.MaxValue, "maxSize");
     }
     ArgumentValidator.EnsureArgumentNotNull(keyExtractor, "keyExtractor");
     ArgumentValidator.EnsureArgumentNotNull(sizeExtractor, "sizeExtractor");
     this.maxSize       = maxSize;
     this.keyExtractor  = keyExtractor;
     this.sizeExtractor = sizeExtractor;
     this.chainedCache  = chainedCache;
     // deque = new TopDeque<TKey, KeyValuePair<TKey, TItem>>(1 + (int) maxSize);
     deque = new TopDeque <TKey, KeyValuePair <TKey, TItem> >();
 }
예제 #3
0
 /// <summary>
 /// 初始化指定容量的缓存实例。
 /// </summary>
 /// <param name="maxSize"></param>
 public LruCache(long capacity)
 {
     this.capacity = capacity;
     this.deque    = new TopDeque <TKey, KeyValuePair <TKey, TValue> >();
 }