private void RemoveFromCache(MemoryCacheEntry entry, CacheEntryRemovedReason reason, bool delayRelease = false)
        {
            // release outside of lock
            if (entry != null)
            {
                if (entry.InExpires())
                {
                    _expires.Remove(entry);
                }

                if (entry.InUsage())
                {
                    _usage.Remove(entry);
                }

                Dbg.Assert(entry.State == EntryState.RemovingFromCache, "entry.State = EntryState.RemovingFromCache");

                entry.State = EntryState.RemovedFromCache;
                if (!delayRelease)
                {
                    entry.Release(_cache, reason);
                }
                if (_perfCounters != null)
                {
                    _perfCounters.Decrement(PerfCounterName.Entries);
                    _perfCounters.Increment(PerfCounterName.Turnover);
                }
            }
        }
Beispiel #2
0
        // private members

        private void AddToCache(MemoryCacheEntry entry)
        {
            // add outside of lock
            if (entry == null)
            {
                return;
            }

            if (entry.HasExpiration())
            {
                _expires.Add(entry);
            }

            if (entry.HasUsage() &&
                (!entry.HasExpiration() || entry.UtcAbsExp - DateTime.UtcNow >= CacheUsage.MIN_LIFETIME_FOR_USAGE))
            {
                _usage.Add(entry);
            }

            // One last sanity check to be sure we didn't fall victim to an Add concurrency
            if (!entry.CompareExchangeState(EntryState.AddedToCache, EntryState.AddingToCache))
            {
                if (entry.InExpires())
                {
                    _expires.Remove(entry);
                }

                if (entry.InUsage())
                {
                    _usage.Remove(entry);
                }
            }

            entry.CallNotifyOnChanged();
            if (_perfCounters != null)
            {
                _perfCounters.Increment(PerfCounterName.Entries);
                _perfCounters.Increment(PerfCounterName.Turnover);
            }
        }
        private void RemoveFromCache(MemoryCacheEntry entry, CacheEntryRemovedReason reason, bool delayRelease = false) {
            // release outside of lock
            if (entry != null) {
                if (entry.InExpires()) {
                    _expires.Remove(entry);
                }

                if (entry.InUsage()) {
                    _usage.Remove(entry);
                }

                Dbg.Assert(entry.State == EntryState.RemovingFromCache, "entry.State = EntryState.RemovingFromCache");

                entry.State = EntryState.RemovedFromCache;
                if (!delayRelease) {
                    entry.Release(_cache, reason);
                }
                if (_perfCounters != null) {
                    _perfCounters.Decrement(PerfCounterName.Entries);
                    _perfCounters.Increment(PerfCounterName.Turnover);
                }
            }
        }
Beispiel #4
0
 private void RemoveFromCache(MemoryCacheEntry entry, CacheEntryRemovedReason reason, bool delayRelease = false)
 {
     if (entry != null)
     {
         if (entry.InExpires())
         {
             this._expires.Remove(entry);
         }
         if (entry.InUsage())
         {
             this._usage.Remove(entry);
         }
         entry.State = EntryState.RemovedFromCache;
         if (!delayRelease)
         {
             entry.Release(this._cache, reason);
         }
         if (this._perfCounters != null)
         {
             this._perfCounters.Decrement(PerfCounterName.Entries);
             this._perfCounters.Increment(PerfCounterName.Turnover);
         }
     }
 }
 private void RemoveFromCache(MemoryCacheEntry entry, CacheEntryRemovedReason reason, bool delayRelease = false)
 {
     if (entry != null)
     {
         if (entry.InExpires())
         {
             this._expires.Remove(entry);
         }
         if (entry.InUsage())
         {
             this._usage.Remove(entry);
         }
         entry.State = EntryState.RemovedFromCache;
         if (!delayRelease)
         {
             entry.Release(this._cache, reason);
         }
         if (this._perfCounters != null)
         {
             this._perfCounters.Decrement(PerfCounterName.Entries);
             this._perfCounters.Increment(PerfCounterName.Turnover);
         }
     }
 }