// 'updatePerfCounters' defaults to true since this method is called by all Get() operations
        // to update both the performance counters and the sliding expiration. Callers that perform
        // nested sliding expiration updates (like a MemoryCacheEntry touching its update sentinel)
        // can pass false to prevent these from unintentionally showing up in the perf counters.
        internal void UpdateExpAndUsage(MemoryCacheEntry entry, bool updatePerfCounters = true)
        {
            if (entry != null)
            {
                if (entry.InUsage() || entry.SlidingExp > TimeSpan.Zero)
                {
                    DateTime utcNow = DateTime.UtcNow;
                    entry.UpdateSlidingExp(utcNow, _expires);
                    entry.UpdateUsage(utcNow, _usage);
                }

                // DevDiv #67021: If this entry has an update sentinel, the sliding expiration is actually associated
                // with that sentinel, not with this entry. We need to update the sentinel's sliding expiration to
                // keep the sentinel from expiring, which in turn would force a removal of this entry from the cache.
                entry.UpdateSlidingExpForUpdateSentinel();

                if (updatePerfCounters && _perfCounters != null)
                {
                    _perfCounters.Increment(PerfCounterName.Hits);
                    _perfCounters.Increment(PerfCounterName.HitRatio);
                    _perfCounters.Increment(PerfCounterName.HitRatioBase);
                }
            }
            else
            {
                if (updatePerfCounters && _perfCounters != null)
                {
                    _perfCounters.Increment(PerfCounterName.Misses);
                    _perfCounters.Increment(PerfCounterName.HitRatioBase);
                }
            }
        }
Example #2
0
 private void UpdateExpAndUsage(MemoryCacheEntry entry)
 {
     if (entry != null)
     {
         if (entry.InUsage() || (entry.SlidingExp > TimeSpan.Zero))
         {
             DateTime utcNow = DateTime.UtcNow;
             entry.UpdateSlidingExp(utcNow, this._expires);
             entry.UpdateUsage(utcNow, this._usage);
         }
         if (this._perfCounters != null)
         {
             this._perfCounters.Increment(PerfCounterName.Hits);
             this._perfCounters.Increment(PerfCounterName.HitRatio);
             this._perfCounters.Increment(PerfCounterName.HitRatioBase);
         }
     }
     else if (this._perfCounters != null)
     {
         this._perfCounters.Increment(PerfCounterName.Misses);
         this._perfCounters.Increment(PerfCounterName.HitRatioBase);
     }
 }
        // 'updatePerfCounters' defaults to true since this method is called by all Get() operations
        // to update both the performance counters and the sliding expiration. Callers that perform
        // nested sliding expiration updates (like a MemoryCacheEntry touching its update sentinel)
        // can pass false to prevent these from unintentionally showing up in the perf counters.
        internal void UpdateExpAndUsage(MemoryCacheEntry entry, bool updatePerfCounters = true) {
            if (entry != null) {
                if (entry.InUsage() || entry.SlidingExp > TimeSpan.Zero) {
                    DateTime utcNow = DateTime.UtcNow;
                    entry.UpdateSlidingExp(utcNow, _expires);
                    entry.UpdateUsage(utcNow, _usage);
                }

                // DevDiv #67021: If this entry has an update sentinel, the sliding expiration is actually associated
                // with that sentinel, not with this entry. We need to update the sentinel's sliding expiration to
                // keep the sentinel from expiring, which in turn would force a removal of this entry from the cache.
                entry.UpdateSlidingExpForUpdateSentinel();

                if (updatePerfCounters && _perfCounters != null) {
                    _perfCounters.Increment(PerfCounterName.Hits);
                    _perfCounters.Increment(PerfCounterName.HitRatio);
                    _perfCounters.Increment(PerfCounterName.HitRatioBase);
                }
            }
            else {
                if (updatePerfCounters && _perfCounters != null) {
                    _perfCounters.Increment(PerfCounterName.Misses);
                    _perfCounters.Increment(PerfCounterName.HitRatioBase);
                }
            }
        }
 private void UpdateExpAndUsage(MemoryCacheEntry entry)
 {
     if (entry != null)
     {
         if (entry.InUsage() || (entry.SlidingExp > TimeSpan.Zero))
         {
             DateTime utcNow = DateTime.UtcNow;
             entry.UpdateSlidingExp(utcNow, this._expires);
             entry.UpdateUsage(utcNow, this._usage);
         }
         if (this._perfCounters != null)
         {
             this._perfCounters.Increment(PerfCounterName.Hits);
             this._perfCounters.Increment(PerfCounterName.HitRatio);
             this._perfCounters.Increment(PerfCounterName.HitRatioBase);
         }
     }
     else if (this._perfCounters != null)
     {
         this._perfCounters.Increment(PerfCounterName.Misses);
         this._perfCounters.Increment(PerfCounterName.HitRatioBase);
     }
 }