System.Web.Caching.CacheItemPriorityQueue.Peek C# (CSharp) Method

Peek() public method

public Peek ( ) : System.Web.Caching.CacheItem
return System.Web.Caching.CacheItem
		public CacheItem Peek ()
		{
			CacheItem ret;
			
			try {
				queueLock.EnterReadLock ();
				if (heap == null || heapCount == 0)
					return null;

				ret = heap [0];
				AddSequenceEntry (ret, EDSequenceEntryType.Peek);
				
				return ret;
			} finally {
				// See comment at the top of the file, above queueLock declaration
				queueLock.ExitReadLock ();
			}
		}
		

Usage Example

        void ExpireItems(object data)
        {
            DateTime  now  = DateTime.Now;
            CacheItem item = null;

            expirationTimer.Change(Timeout.Infinite, Timeout.Infinite);
            try
            {
                cacheLock.EnterWriteLock();
                while (true)
                {
                    item = timedItems.Peek();

                    if (item == null)
                    {
                        if (timedItems.Count == 0)
                        {
                            break;
                        }

                        timedItems.Dequeue();
                        continue;
                    }

                    if (!item.Disabled && item.ExpiresAt > now.Ticks)
                    {
                        break;
                    }

                    if (item.Disabled)
                    {
                        item = timedItems.Dequeue();
                        continue;
                    }

                    item = timedItems.Dequeue();
                    if (item != null)
                    {
                        if (!NeedsUpdate(item, CacheItemUpdateReason.Expired, false))
                        {
                            Remove(item.Key, CacheItemRemovedReason.Expired, false, true);
                        }
                    }
                }
            }
            finally
            {
                // See comment at the top of the file, above cacheLock declaration
                cacheLock.ExitWriteLock();
            }

            if (item != null)
            {
                long remaining = Math.Max(0, (long)(item.AbsoluteExpiration - now).TotalMilliseconds);
                if (remaining > 0 && expirationTimerPeriod > remaining)
                {
                    expirationTimerPeriod = remaining;
                }

                expirationTimer.Change(expirationTimerPeriod, expirationTimerPeriod);
                return;
            }

            expirationTimer.Change(Timeout.Infinite, Timeout.Infinite);
            expirationTimerPeriod = 0;
        }
All Usage Examples Of System.Web.Caching.CacheItemPriorityQueue::Peek