Пример #1
0
        private void WriteItem(BaseReference itemRef)
        {
            ItemHolder  item  = itemRef.Item;
            IStorable   item2 = item.Item;
            ReferenceID id    = itemRef.Id;
            long        num   = m_storage.Allocate(item2);

            if (id.HasMultiPart && !id.IsTemporary)
            {
                m_partitionManager.UpdateTreePartitionOffset(id, num);
                if (itemRef.PinCount == 0)
                {
                    CacheRemoveValue(id);
                }
            }
            else
            {
                id              = new ReferenceID(num);
                id.IsTemporary  = false;
                id.HasMultiPart = false;
                itemRef.Id      = id;
            }
            if (itemRef.PinCount == 0)
            {
                item.Item      = null;
                item.Reference = null;
                itemRef.Item   = null;
            }
        }
Пример #2
0
 public void Add(ItemHolder item)
 {
     m_count++;
     item.Next                = m_sentinal;
     item.Previous            = m_sentinal.Previous;
     m_sentinal.Previous.Next = item;
     m_sentinal.Previous      = item;
 }
Пример #3
0
 public void Bump(ItemHolder item)
 {
     item.Previous.Next       = item.Next;
     item.Next.Previous       = item.Previous;
     item.Next                = m_sentinal;
     item.Previous            = m_sentinal.Previous;
     m_sentinal.Previous.Next = item;
     m_sentinal.Previous      = item;
 }
Пример #4
0
        public T ExtractLRU()
        {
            if (m_count == 0)
            {
                Global.Tracer.Assert(condition: false, "Cannot ExtractLRU from empty cache");
            }
            ItemHolder next = m_sentinal.Next;

            Remove(next);
            return((T)next);
        }
Пример #5
0
        protected sealed override void FulfillInProgressFree()
        {
            int num = m_cachePriority.Count;

            while (m_inProgressFreeBytes > 0 && num > 0)
            {
                num--;
                ItemHolder    itemHolder = m_cachePriority.Peek();
                BaseReference reference  = itemHolder.Reference;
                if (reference.PinCount == 0)
                {
                    m_cachePriority.ExtractLRU();
                    reference.InQueue = InQueueState.None;
                    if (itemHolder.Item != null)
                    {
                        UpdateStatsForRemovedItem(reference, ref m_inProgressFreeBytes);
                        CacheRemoveValue(reference.Id);
                        itemHolder.Item      = null;
                        itemHolder.Reference = null;
                        reference.Item       = null;
                    }
                }
                else
                {
                    m_cachePriority.Bump(itemHolder);
                }
            }
            if (m_inProgressFreeBytes <= 0)
            {
                return;
            }
            using (IDecumulator <BaseReference> decumulator = m_serializationQueue.GetDecumulator())
            {
                while (m_inProgressFreeBytes > 0 && decumulator.MoveNext())
                {
                    BaseReference current = decumulator.Current;
                    decumulator.RemoveCurrent();
                    if (current.Item != null)
                    {
                        if (current.PinCount == 0)
                        {
                            UpdateStatsForRemovedItem(current, ref m_inProgressFreeBytes);
                        }
                        WriteItem(current);
                        if (current.PinCount > 0)
                        {
                            EnqueueItem(current);
                            CacheSetValue(current.Id, current);
                        }
                    }
                }
            }
        }
Пример #6
0
 public void Remove(ItemHolder item)
 {
     if (m_count == 0)
     {
         Global.Tracer.Assert(condition: false, "Cannot ExtractLRU from empty cache");
     }
     m_count--;
     item.Previous.Next = item.Next;
     item.Next.Previous = item.Previous;
     item.Next          = null;
     item.Previous      = null;
 }
Пример #7
0
        public sealed override IReference <T> GenerateFixedReference <T>(T obj)
        {
            BaseReference baseReference = CreateReference(obj);

            baseReference.Init(this, GenerateTempId());
            ItemHolder itemHolder = new ItemHolder();

            itemHolder.Reference  = baseReference;
            itemHolder.Item       = obj;
            baseReference.Item    = itemHolder;
            baseReference.InQueue = InQueueState.InQueue;
            return((IReference <T>)baseReference);
        }
Пример #8
0
        private void CacheItem(BaseReference reference, IStorable item, bool fromDeserialize, int newItemSize)
        {
            ItemHolder itemHolder = new ItemHolder();

            itemHolder.Reference = reference;
            itemHolder.Item      = item;
            reference.Item       = itemHolder;
            FreeCacheSpace(newItemSize, m_cacheFreeableBytes);
            if (fromDeserialize)
            {
                CacheSetValue(reference.Id, reference);
                m_cacheFreeableBytes += newItemSize;
            }
            else
            {
                m_totalAuditedBytes += newItemSize;
            }
            m_cacheSizeBytes += newItemSize;
            EnqueueItem(reference);
        }
Пример #9
0
 internal sealed override void UnPin(BaseReference reference)
 {
     if (reference.PinCount == 0 && (reference.Id.IsTemporary || reference.Id.HasMultiPart) && reference.InQueue == InQueueState.None)
     {
         reference.InQueue = InQueueState.InQueue;
         m_serializationQueue.Enqueue(reference);
         if (!m_lockedDownForFlush)
         {
             ItemHolder item = reference.Item;
             IStorable  obj  = null;
             if (item != null)
             {
                 obj = item.Item;
             }
             m_cacheFreeableBytes += ItemSizes.SizeOf(obj);
         }
     }
     if (!m_lockedDownForFlush)
     {
         PeriodicOperationCheck();
     }
 }
Пример #10
0
 public LinkedLRUCache()
 {
     m_sentinal = new ItemHolder();
     Clear();
 }