internal long TrimInternal(int percent) { int count = Count; int toTrim = 0; // do we need to drop a percentage of entries? if (percent > 0) { toTrim = (int)(((long)count * (long)percent) / 100L); // would this leave us above MAX_COUNT? int minTrim = count - MAX_COUNT; if (toTrim < minTrim) { toTrim = minTrim; } // would this put us below MIN_COUNT? int maxTrim = count - MIN_COUNT; if (toTrim > maxTrim) { toTrim = maxTrim; } } // do we need to trim? if (toTrim <= 0 || _disposed == 1) { return(0); } int trimmed = 0; // total number of entries trimmed int trimmedOrExpired = 0; #if DBG int beginTotalCount = count; #endif trimmedOrExpired = _expires.FlushExpiredItems(true); if (trimmedOrExpired < toTrim) { trimmed = _usage.FlushUnderUsedItems(toTrim - trimmedOrExpired); trimmedOrExpired += trimmed; } if (trimmed > 0 && _perfCounters != null) { // Update values for perfcounters _perfCounters.IncrementBy(PerfCounterName.Trims, trimmed); } #if DBG Dbg.Trace("MemoryCacheStore", "TrimInternal:" + " beginTotalCount=" + beginTotalCount + ", endTotalCount=" + count + ", percent=" + percent + ", trimmed=" + trimmed); #endif return(trimmedOrExpired); }