Пример #1
0
        public void InsertOrUpdate(string partition, IPageCacheItem page)
        {
            var cacheKey   = MakeCacheKey(partition, page.Id);
            var cacheEntry = new KeyValuePair <string, IPageCacheItem>(partition, page);
            LinkedListNode <KeyValuePair <string, IPageCacheItem> > cacheNode;

            lock (_updateLock)
            {
                if (_cacheItems.TryGetValue(cacheKey, out cacheNode))
                {
                    cacheNode.Value = cacheEntry;
                    _accessList.Remove(cacheNode);
                    _accessList.AddFirst(cacheNode);
#if DEBUG_PAGECACHE
                    Logging.LogDebug("LruPageCache.InsertOrUpdate: Updated {0}", cacheKey);
#endif
                }
                else
                {
                    var listNode = new LinkedListNode <KeyValuePair <string, IPageCacheItem> >(cacheEntry);
                    _accessList.AddFirst(listNode);
                    _cacheItems[cacheKey] = listNode;
                    _count++;
#if DEBUG_PAGECACHE
                    Logging.LogDebug("LruPageCache.InsertOrUpdate: Inserted {0}", cacheKey);
#endif
                    if (_count > _highWaterMark)
                    {
                        EvictItems();
                    }
                }
            }
            Debug.Assert(_count == _cacheItems.Count, "Internal count is out of sync with _cacheItems count.");
        }
Пример #2
0
        public void InsertOrUpdate(string partition, IPageCacheItem page)
        {
            var cacheKey = MakeCacheKey(partition, page.Id);
            var cacheEntry = new KeyValuePair<string, IPageCacheItem>(partition, page);
            LinkedListNode<KeyValuePair<string, IPageCacheItem>> cacheNode;
            lock (_updateLock)
            {
                if (_cacheItems.TryGetValue(cacheKey, out cacheNode))
                {
                    cacheNode.Value = cacheEntry;
                    _accessList.Remove(cacheNode);
                    _accessList.AddFirst(cacheNode);
#if DEBUG_PAGECACHE
                    Logging.LogDebug("LruPageCache.InsertOrUpdate: Updated {0}", cacheKey);
#endif
                }
                else
                {
                    var listNode = new LinkedListNode<KeyValuePair<string, IPageCacheItem>>(cacheEntry);
                    _accessList.AddFirst(listNode);
                    _cacheItems[cacheKey] = listNode;
                    _count++;
#if DEBUG_PAGECACHE
                    Logging.LogDebug("LruPageCache.InsertOrUpdate: Inserted {0}", cacheKey);
#endif
                    if (_count > _highWaterMark)
                    {
                        EvictItems();
                    }
                }
            }
            Debug.Assert(_count == _cacheItems.Count, "Internal count is out of sync with _cacheItems count.");
        }
 public void InsertOrUpdate(string partition, IPageCacheItem page)
 {
     var ppk = new PartitionPageKey(AssertPartitionId(partition), page.Id);
     _pages.Insert(ppk, page);
 }
Пример #4
0
        public void InsertOrUpdate(string partition, IPageCacheItem page)
        {
            var ppk = new PartitionPageKey(AssertPartitionId(partition), page.Id);

            _pages.Insert(ppk, page);
        }