1 // This file implements the classes ExpiresEntryRef and CacheExpires missing from .NET reference source
3 using System.Threading;
5 namespace System.Runtime.Caching
9 public static ExpiresEntryRef INVALID = new ExpiresEntryRef ();
11 public bool IsInvalid {
12 get { return this == INVALID; }
16 class CacheExpiresHelper : ICacheEntryHelper
18 public int Compare(MemoryCacheEntry entry1, MemoryCacheEntry entry2)
20 return DateTime.Compare (entry1.UtcAbsExp , entry2.UtcAbsExp);
23 public DateTime GetDateTime (MemoryCacheEntry entry)
25 return entry.UtcAbsExp;
29 class CacheExpires : CacheEntryCollection
32 public static TimeSpan MIN_UPDATE_DELTA = new TimeSpan (0, 0, 1);
33 public static TimeSpan EXPIRATIONS_INTERVAL = new TimeSpan (0, 0, 20);
34 public static CacheExpiresHelper helper = new CacheExpiresHelper ();
38 public CacheExpires (MemoryCacheStore store)
39 : base (store, helper)
43 public void Add (MemoryCacheEntry entry)
45 entry.ExpiresEntryRef = new ExpiresEntryRef ();
49 public void Remove (MemoryCacheEntry entry)
52 entry.ExpiresEntryRef = ExpiresEntryRef.INVALID;
55 public void UtcUpdate (MemoryCacheEntry entry, DateTime utcAbsExp)
58 entry.UtcAbsExp = utcAbsExp;
62 public void EnableExpirationTimer (bool enable)
68 var period = (int) EXPIRATIONS_INTERVAL.TotalMilliseconds;
69 timer = new Timer ((o) => FlushExpiredItems (true), null, period, period);
76 public int FlushExpiredItems (bool blockInsert)
78 return base.FlushItems (DateTime.UtcNow, CacheEntryRemovedReason.Expired, blockInsert);