public void Hit <T>(T value, NLinkedList <T> link, Func <T, T, bool> compare) { lock (link) { var next = link.First; LinkedListNode <T> hitNode = null; while (next != null) { if (compare(value, next.Value)) { hitNode = next; } next = next.Next; } if (hitNode == null) { link.AddFirst(value); } else { link.AddFirst(hitNode); } } }
public HashLinkedCache() { _tempDict = new ConcurrentDictionary <TKey, TValue>(); _linked = new NLinkedList <KeyValuePair <TKey, TValue> >(); _dict = new ConcurrentDictionary <TKey, LinkedListNode <KeyValuePair <TKey, TValue> > >(); _linkedStrategy = new NLinkedListStrategyLRU(); _length = 1000; _linked.MaxLength = _length; _linked.OnAdded = (node, value) => { _dict[value.Key] = node; _tempDict.TryRemove(value.Key, out TValue v); }; _linked.OnRemoved = (value) => { _dict.TryRemove(value.Key, out LinkedListNode <KeyValuePair <TKey, TValue> > v); _tempDict.TryRemove(value.Key, out TValue tv); }; }
public HashLinkedCacheForMemoryFile(int fileCount, int fileSize) { _linked = new NLinkedList <KeyValuePair <TKey, TKey> >(); _dict = new ConcurrentDictionary <TKey, LinkedListNode <KeyValuePair <TKey, TKey> > >(); _linkedStrategy = new NLinkedListStrategyLRU(); _length = 1000; _linked.MaxLength = _length; _linked.OnAdded = (node, value) => { _dict[value.Key] = node; }; _linked.OnRemoved = (value) => { _dict.TryRemove(value.Key, out LinkedListNode <KeyValuePair <TKey, TKey> > v); }; try { for (var index = 0; index <= fileCount - 1; index++) { _memoryFileList[index] = MemoryMappedFile.CreateOrOpen(Guid.NewGuid().ToString(), (long)1024 * 1024 * fileSize); } } catch { foreach (var item in _memoryFileList) { try { item.Value.Dispose(); } catch { } throw; } } }
public void Hit <T>(LinkedListNode <T> node, NLinkedList <T> link) { link.AddFirst(node); }
public void Add <T>(T value, NLinkedList <T> link) { link.AddFirst(value); }
public void Hit <T>(LinkedListNode <T> node, NLinkedList <T> link) { }