/// <summary> /// Occurs when the item with the given key is used. /// </summary> /// <param name="key">Item key.</param> private void OnItemUsed(TKey key) { int itemIndex = -1; if (key != null) { lock (_lock) { itemIndex = Recency.IndexOf(key); if (itemIndex != 0) { Recency.RemoveAt(itemIndex); Recency.Insert(0, key); } } } }
/// <summary> /// Removes the item with the given key. /// </summary> /// <param name="key">Item key.</param> private void RemoveInternal(TKey key) { int itemIndex = -1; TValue removedValue = default(TValue); if (key != null && ContainsKey(key)) { lock (_lock) { itemIndex = Recency.IndexOf(key); // Removing from the recency Recency.RemoveAt(itemIndex); } // Removing from the data Data.TryRemove(key, out removedValue); } }