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; } } }