/// <summary>Add an item to the cache</summary> private Node AddAndGetNode(object value) { if (value == null) { return(null); } // see if item is already in index Node node = null; IIndex[] indexs; lock (_indexList) { indexs = _indexList.ToArray(); } foreach (var index in indexs) { if ((node = index.GetNode(value)) != null) { break; } } // dupl is used to prevent total count from growing when item is already in indexes (only new Nodes) bool isDupl = (node != null && node.Value == value); if (!isDupl) { node = _lifeSpan.Add(value); } // make sure node gets inserted into all indexes foreach (var index in indexs) { if (!index.AddNode(node)) { isDupl = true; } } if (!isDupl) { Interlocked.Increment(ref _totalCount); } return(node); }
/// <summary>Add an item to the cache</summary> private INode Add(ItemType item) { if (item == null) { return(null); } // see if item is already in index INode node = null; foreach (KeyValuePair <string, IIndex> keyValue in _indexList) { if ((node = keyValue.Value.FindItem(item)) != null) { break; } } // dupl is used to prevent total count from growing when item is already in indexes (only new Nodes) bool isDupl = (node != null && node.Value == item); if (!isDupl) { node = _lifeSpan.Add(item); } // make sure node gets inserted into all indexes foreach (KeyValuePair <string, IIndex> keyValue in _indexList) { if (!keyValue.Value.AddItem(node)) { isDupl = true; } } if (!isDupl) { Interlocked.Increment(ref _totalCount); } return(node); }