예제 #1
0
 /// <summary>
 /// 添加Key-Value的缓存记录
 /// </summary>
 public void Add(object key, object value)
 {
     object tempKey = _keys[_latestIndex % _capacity];
     _keys[_latestIndex % _capacity] = key;
     if (ContainsKey(key))
     {
         ((CyclingBuffer)_hashSet[key]).Update(value);
     }
     else
     {
         Count++;
         if (Count > _capacity)
         {
             _hashSet.Remove(tempKey);
             Count--;
         }
         CyclingBuffer buffer = new CyclingBuffer();
         buffer.Update(value);
         _hashSet.Add(key, buffer);
     }
     _latestIndex++;
     _latestIndex %= _capacity;
 }
예제 #2
0
        /// <summary>
        /// 添加Key-Value的缓存记录
        /// </summary>
        public void Add(object key, object value)
        {
            object tempKey = _keys[_latestIndex % _capacity];

            _keys[_latestIndex % _capacity] = key;
            if (ContainsKey(key))
            {
                ((CyclingBuffer)_hashSet[key]).Update(value);
            }
            else
            {
                Count++;
                if (Count > _capacity)
                {
                    _hashSet.Remove(tempKey);
                    Count--;
                }
                CyclingBuffer buffer = new CyclingBuffer();
                buffer.Update(value);
                _hashSet.Add(key, buffer);
            }
            _latestIndex++;
            _latestIndex %= _capacity;
        }