/// <summary> /// Inserts key-value into full cache. /// </summary> /// <param name="key">The key.</param> /// <param name="value">The value.</param> private void InsertIntoFullCache(TKey key, TValue value) { if (BlockSetsLookup.ContainsKey(key)) { CacheBlockSet <TKey, TValue> blockSet = BlockSetsLookup[key]; if (blockSet != null) { blockSet.Add(key, value); } } else { CacheBlockSet <TKey, TValue> insertableBlockSet = discardBlock(BlockSetsLookup); AddBlockSetToCache(key, value, insertableBlockSet); } }
/// <summary> /// Adds the block set to cache. /// </summary> /// <param name="key">The key.</param> /// <param name="value">The value.</param> /// <param name="blockSet">The block set.</param> private void AddBlockSetToCache(TKey key, TValue value, CacheBlockSet <TKey, TValue> blockSet) { CacheBlock <TKey, TValue> cacheItem = null; if (blockSet != null) { cacheItem = blockSet.Add(key, value); } var blocksets = BlockSetsLookup.Values; if (!blocksets.Any(a => a.Blocks.Any(b => b.Key.Equals(key)))) { BlockSetsLookup.Add(key, blockSet); } this.lruList.AddLast(cacheItem); }