internal int FlushExpiredItems(DateTime utcNow, bool useInsertBlock) { ExpiresEntry[] entryArray; int index; CacheEntry entry; ExpiresEntryRef ref3; ExpiresEntryRef ref4; if ((this._cEntriesInUse == 0) || (this.GetExpiresCount(utcNow) == 0)) { return(0); } ExpiresEntryRef iNVALID = ExpiresEntryRef.INVALID; int num2 = 0; try { if (useInsertBlock) { this._cacheExpires.CacheSingle.BlockInsertIfNeeded(); } lock (this) { if ((this._cEntriesInUse == 0) || (this.GetExpiresCount(utcNow) == 0)) { return(0); } this.ResetCounts(utcNow); int num3 = this._cPagesInUse; for (int i = 0; i < this._pages.Length; i++) { entryArray = this._pages[i]._entries; if (entryArray != null) { int num5 = 0x7f - entryArray[0]._cFree; for (int j = 1; j < entryArray.Length; j++) { entry = entryArray[j]._cacheEntry; if (entry != null) { if (entryArray[j]._utcExpires > utcNow) { this.AddCount(entryArray[j]._utcExpires); } else { entry.ExpiresBucket = 0xff; entry.ExpiresEntryRef = ExpiresEntryRef.INVALID; entryArray[j]._cFree = 1; entryArray[j]._next = iNVALID; iNVALID = new ExpiresEntryRef(i, j); num2++; this._cEntriesInFlush++; } num5--; if (num5 == 0) { break; } } } num3--; if (num3 == 0) { break; } } } if (num2 == 0) { return(0); } this._blockReduce = true; } } finally { if (useInsertBlock) { this._cacheExpires.CacheSingle.UnblockInsert(); } } CacheSingle cacheSingle = this._cacheExpires.CacheSingle; for (ref3 = iNVALID; !ref3.IsInvalid; ref3 = ref4) { entryArray = this._pages[ref3.PageIndex]._entries; index = ref3.Index; ref4 = entryArray[index]._next; entry = entryArray[index]._cacheEntry; entryArray[index]._cacheEntry = null; cacheSingle.Remove(entry, CacheItemRemovedReason.Expired); } try { if (useInsertBlock) { this._cacheExpires.CacheSingle.BlockInsertIfNeeded(); } lock (this) { for (ref3 = iNVALID; !ref3.IsInvalid; ref3 = ref4) { entryArray = this._pages[ref3.PageIndex]._entries; index = ref3.Index; ref4 = entryArray[index]._next; this._cEntriesInFlush--; this.AddExpiresEntryToFreeList(ref3); } this._blockReduce = false; this.Reduce(); } } finally { if (useInsertBlock) { this._cacheExpires.CacheSingle.UnblockInsert(); } } return(num2); }
internal int FlushUnderUsedItems(int maxFlush, bool force, ref int publicEntriesFlushed, ref int ocEntriesFlushed) { UsageEntry[] entryArray; int num; CacheEntry entry; UsageEntryRef ref6; UsageEntryRef ref7; if (this._cEntriesInUse == 0) { return(0); } UsageEntryRef iNVALID = UsageEntryRef.INVALID; int num2 = 0; try { this._cacheUsage.CacheSingle.BlockInsertIfNeeded(); lock (this) { UsageEntryRef ref4; if (this._cEntriesInUse == 0) { return(0); } DateTime utcNow = DateTime.UtcNow; for (UsageEntryRef ref3 = this._lastRefTail; (this._cEntriesInFlush < maxFlush) && !ref3.IsInvalid; ref3 = ref4) { for (ref4 = this._pages[ref3.PageIndex]._entries[ref3.Ref2Index]._ref2._prev; ref4.IsRef1; ref4 = this._pages[ref4.PageIndex]._entries[ref4.Ref1Index]._ref1._prev) { } entryArray = this._pages[ref3.PageIndex]._entries; num = ref3.Ref2Index; if (!force) { DateTime time = entryArray[num]._utcDate; if (((utcNow - time) <= CacheUsage.NEWADD_INTERVAL) && (utcNow >= time)) { continue; } } UsageEntryRef entryRef = new UsageEntryRef(ref3.PageIndex, ref3.Ref2Index); entry = entryArray[num]._cacheEntry; entry.UsageEntryRef = UsageEntryRef.INVALID; if (entry.IsPublic) { publicEntriesFlushed++; } else if (entry.IsOutputCache) { ocEntriesFlushed++; } this.RemoveEntryFromLastRefList(entryRef); entryArray[num]._ref1._next = iNVALID; iNVALID = entryRef; num2++; this._cEntriesInFlush++; } if (num2 == 0) { return(0); } this._blockReduce = true; } } finally { this._cacheUsage.CacheSingle.UnblockInsert(); } CacheSingle cacheSingle = this._cacheUsage.CacheSingle; for (ref6 = iNVALID; !ref6.IsInvalid; ref6 = ref7) { entryArray = this._pages[ref6.PageIndex]._entries; num = ref6.Ref1Index; ref7 = entryArray[num]._ref1._next; entry = entryArray[num]._cacheEntry; entryArray[num]._cacheEntry = null; cacheSingle.Remove(entry, CacheItemRemovedReason.Underused); } try { this._cacheUsage.CacheSingle.BlockInsertIfNeeded(); lock (this) { for (ref6 = iNVALID; !ref6.IsInvalid; ref6 = ref7) { entryArray = this._pages[ref6.PageIndex]._entries; num = ref6.Ref1Index; ref7 = entryArray[num]._ref1._next; this._cEntriesInFlush--; this.AddUsageEntryToFreeList(ref6); } this._blockReduce = false; this.Reduce(); } } finally { this._cacheUsage.CacheSingle.UnblockInsert(); } return(num2); }