private void WriteItem(BaseReference itemRef)
        {
            ItemHolder  item  = itemRef.Item;
            IStorable   item2 = item.Item;
            ReferenceID id    = itemRef.Id;
            long        num   = base.m_storage.Allocate(item2);

            if (id.HasMultiPart && !id.IsTemporary)
            {
                this.m_partitionManager.UpdateTreePartitionOffset(id, num);
                if (itemRef.PinCount == 0)
                {
                    this.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;
            }
        }
 public void Add(ItemHolder item)
 {
     this.m_count++;
     item.Next     = this.m_sentinal;
     item.Previous = this.m_sentinal.Previous;
     this.m_sentinal.Previous.Next = item;
     this.m_sentinal.Previous      = item;
 }
 public void Bump(ItemHolder item)
 {
     item.Previous.Next            = item.Next;
     item.Next.Previous            = item.Previous;
     item.Next                     = this.m_sentinal;
     item.Previous                 = this.m_sentinal.Previous;
     this.m_sentinal.Previous.Next = item;
     this.m_sentinal.Previous      = item;
 }
        public T ExtractLRU()
        {
            if (this.m_count == 0)
            {
                Global.Tracer.Assert(false, "Cannot ExtractLRU from empty cache");
            }
            ItemHolder next = this.m_sentinal.Next;

            this.Remove(next);
            return((T)next);
        }
 public void Remove(ItemHolder item)
 {
     if (this.m_count == 0)
     {
         Global.Tracer.Assert(false, "Cannot ExtractLRU from empty cache");
     }
     this.m_count--;
     item.Previous.Next = item.Next;
     item.Next.Previous = item.Previous;
     item.Next          = null;
     item.Previous      = null;
 }
        protected sealed override void FulfillInProgressFree()
        {
            int num = this.m_cachePriority.Count;

            while (base.m_inProgressFreeBytes > 0 && num > 0)
            {
                num--;
                ItemHolder    itemHolder = this.m_cachePriority.Peek();
                BaseReference reference  = itemHolder.Reference;
                if (reference.PinCount == 0)
                {
                    this.m_cachePriority.ExtractLRU();
                    reference.InQueue = InQueueState.None;
                    if (itemHolder.Item != null)
                    {
                        this.UpdateStatsForRemovedItem(reference, ref base.m_inProgressFreeBytes);
                        this.CacheRemoveValue(reference.Id);
                        itemHolder.Item      = null;
                        itemHolder.Reference = null;
                        reference.Item       = null;
                    }
                }
                else
                {
                    this.m_cachePriority.Bump(itemHolder);
                }
            }
            if (base.m_inProgressFreeBytes > 0)
            {
                using (IDecumulator <BaseReference> decumulator = this.m_serializationQueue.GetDecumulator())
                {
                    while (base.m_inProgressFreeBytes > 0 && decumulator.MoveNext())
                    {
                        BaseReference current = decumulator.Current;
                        decumulator.RemoveCurrent();
                        if (current.Item != null)
                        {
                            if (current.PinCount == 0)
                            {
                                this.UpdateStatsForRemovedItem(current, ref base.m_inProgressFreeBytes);
                            }
                            this.WriteItem(current);
                            if (current.PinCount > 0)
                            {
                                this.EnqueueItem(current);
                                this.CacheSetValue(current.Id, current);
                            }
                        }
                    }
                }
            }
        }
        public sealed override IReference <T> GenerateFixedReference <T>(T obj)
        {
            BaseReference baseReference = base.CreateReference((IStorable)(object)obj);

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

            itemHolder.Reference  = baseReference;
            itemHolder.Item       = (IStorable)(object)obj;
            baseReference.Item    = itemHolder;
            baseReference.InQueue = InQueueState.InQueue;
            return((IReference <T>)baseReference);
        }
        private void CacheItem(BaseReference reference, IStorable item, bool fromDeserialize, int newItemSize)
        {
            ItemHolder itemHolder = new ItemHolder();

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