示例#1
0
        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);
                }
            }
        }
示例#2
0
        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);
            };
        }
示例#3
0
        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;
                }
            }
        }
示例#4
0
 public void Hit <T>(LinkedListNode <T> node, NLinkedList <T> link)
 {
     link.AddFirst(node);
 }
示例#5
0
 public void Add <T>(T value, NLinkedList <T> link)
 {
     link.AddFirst(value);
 }
示例#6
0
 public void Hit <T>(LinkedListNode <T> node, NLinkedList <T> link)
 {
 }