public CacheEntryRemovedArguments(ObjectCache source, CacheEntryRemovedReason reason, CacheItem cacheItem) {
     if (source == null) {
         throw new ArgumentNullException("source");
     }
     if (cacheItem == null) {
         throw new ArgumentNullException("cacheItem");
     }
     _source = source;
     _reason = reason;
     _cacheItem = cacheItem;
 }
 public CacheEntryUpdateArguments(ObjectCache source, CacheEntryRemovedReason reason, String key, String regionName) {
     if (source == null) {
         throw new ArgumentNullException("source");
     }
     if (key == null) {
         throw new ArgumentNullException("key");
     }
     _source = source;
     _reason = reason;
     _key = key;
     _regionName = regionName;
 }
		public CacheEntryRemovedArguments (ObjectCache source, CacheEntryRemovedReason reason, CacheItem cacheItem)
		{
			if (source == null)
				throw new ArgumentNullException ("source");

			if (cacheItem == null)
				throw new ArgumentNullException ("cacheItem");
			
			this.CacheItem = cacheItem;
			this.RemovedReason = reason;
			this.Source = source;
		}
		public CacheEntryUpdateArguments (ObjectCache source, CacheEntryRemovedReason reason, string key, string regionName)
		{
			if (source == null)
				throw new ArgumentNullException ("source");

			if (key == null)
				throw new ArgumentNullException ("key");

			this.Key = key;
			this.RegionName = regionName;
			this.RemovedReason = reason;
			this.Source = source;	
		}
 private void CallCacheEntryRemovedCallback(MemoryCache cache, CacheEntryRemovedReason reason)
 {
     if (this._callback != null)
     {
         CacheEntryRemovedArguments arguments = new CacheEntryRemovedArguments(cache, reason, new CacheItem(base.Key, this._value));
         try
         {
             this._callback(arguments);
         }
         catch
         {
         }
     }
 }
 public CacheEntryRemovedArguments(ObjectCache source, CacheEntryRemovedReason reason, System.Runtime.Caching.CacheItem cacheItem)
 {
     if (source == null)
     {
         throw new ArgumentNullException("source");
     }
     if (cacheItem == null)
     {
         throw new ArgumentNullException("cacheItem");
     }
     this._source = source;
     this._reason = reason;
     this._cacheItem = cacheItem;
 }
Exemple #7
0
        async void CleanupCacheItem(Task <TValue> valueTask, string textKey, CacheEntryRemovedReason reason)
        {
            var value = await valueTask.ConfigureAwait(false);

            await _valueRemoved(textKey, value, reason.ToString()).ConfigureAwait(false);

            var disposable = value as IDisposable;

            disposable?.Dispose();

            var asyncDisposable = value as IAsyncDisposable;

            if (asyncDisposable != null)
            {
                await asyncDisposable.DisposeAsync().ConfigureAwait(false);
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="key"></param>
        /// <param name="reason"></param>
        /// <param name="regionName"></param>
        /// <returns></returns>
        public object Remove(string key, CacheEntryRemovedReason reason, string regionName = null)
        {
            if (!string.IsNullOrWhiteSpace(regionName))
            {
                throw new NotSupportedException("Region name not supported");
            }

            if (key == null)
            {
                throw new ArgumentNullException(nameof(key));
            }

            object value;

            this.Data.TryRemove(key, out value);
            return(value);
        }
        public CacheEntryUpdateArguments(ObjectCache source, CacheEntryRemovedReason reason, string key, string regionName)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }

            if (key == null)
            {
                throw new ArgumentNullException("key");
            }

            this.Key           = key;
            this.RegionName    = regionName;
            this.RemovedReason = reason;
            this.Source        = source;
        }
Exemple #10
0
        internal void Set(MemoryCacheKey key, MemoryCacheEntry entry)
        {
            if (_useInsertBlock && entry.HasUsage())
            {
                WaitInsertBlock();
            }
            MemoryCacheEntry existingEntry = null;
            bool             added         = false;

            lock (_entriesLock)
            {
                if (_disposed == 0)
                {
                    existingEntry = _entries[key] as MemoryCacheEntry;
                    if (existingEntry != null)
                    {
                        existingEntry.State = EntryState.RemovingFromCache;
                    }
                    entry.State   = EntryState.AddingToCache;
                    added         = true;
                    _entries[key] = entry;
                }
            }

            CacheEntryRemovedReason reason = CacheEntryRemovedReason.Removed;

            if (existingEntry != null)
            {
                if (existingEntry.UtcAbsExp <= DateTime.UtcNow)
                {
                    reason = CacheEntryRemovedReason.Expired;
                }
                RemoveFromCache(existingEntry, reason, delayRelease: true);
            }
            if (added)
            {
                AddToCache(entry);
            }

            // Call Release after the new entry has been completely added so
            // that the CacheItemRemovedCallback can take a dependency on the newly inserted item.
            if (existingEntry != null)
            {
                existingEntry.Release(_cache, reason);
            }
        }
Exemple #11
0
        private void CallCacheEntryRemovedCallback(MemoryCache cache, CacheEntryRemovedReason reason)
        {
            if (_callback == null)
            {
                return;
            }
            CacheEntryRemovedArguments args = new CacheEntryRemovedArguments(cache, reason, new CacheItem(Key, _value));

            try
            {
                _callback(args);
            }
            catch
            {
                //
            }
        }
Exemple #12
0
        public void Removed(MemoryCache owner, CacheEntryRemovedReason reason)
        {
            if (removedCallback == null)
            {
                Disabled = true;
                return;
            }

            try {
                removedCallback(new CacheEntryRemovedArguments(owner, reason, new CacheItem(Key, Value)));
            } catch {
                // ignore - we don't care about the exceptions thrown inside the
                // handler
            } finally {
                Disabled = true;
            }
        }
        public void Updated(MemoryCache owner, CacheEntryRemovedReason reason)
        {
            if (updateCallback == null)
            {
                return;
            }

            try
            {
                var args = new CacheEntryUpdateArguments(owner, reason, Key, null);
                updateCallback(args);
            }
            catch
            {
                // ignore - we don't care about the exceptions thrown inside the
                // handler
            }
        }
 /// <summary>
 /// </summary>
 /// <param name="removedKey"> </param>
 /// <param name="expiredValue"> </param>
 /// <param name="removalReason"> </param>
 /// <param name="callbackFunction"> </param>
 public ItemExpiredEventArgs(string removedKey, TItem expiredValue, CacheEntryRemovedReason removalReason,
                             CacheEntryRemovedCallback callbackFunction)
 {
     if (removedKey == null)
     {
         throw new ArgumentNullException("removedKey");
     }
     if (callbackFunction == null)
     {
         throw new ArgumentNullException("callbackFunction");
     }
     RemovedKey       = removedKey;
     ExpiredValue     = expiredValue;
     RemovalReason    = removalReason;
     CallbackFunction = callbackFunction;
     ExpirationTime   = DateTime.Now;
     _cachedItem      = expiredValue;
 }
Exemple #15
0
        public object Remove(string key, CacheEntryRemovedReason reason, string regionName = null)
        {
            if (regionName != null)
            {
                throw new NotSupportedException(SR.RegionName_not_supported);
            }
            if (key == null)
            {
                throw new ArgumentNullException(nameof(key));
            }
            if (IsDisposed)
            {
                return(null);
            }
            MemoryCacheEntry entry = RemoveEntry(key, null, reason);

            return((entry != null) ? entry.Value : null);
        }
Exemple #16
0
        internal static void OnRemove(string key, CacheEntryRemovedReason reason)
        {
            if (EnableStatistics)
            {
                lock (@lock)
                {
                    Statistics stat = null;
                    if (_activeStats.TryGetValue(key, out stat))
                    {
                        _activeStats.Remove(key);

                        stat.RemoveUtcDate = DateTime.UtcNow;
                        stat.RemoveReason  = reason;

                        _expiredStats.Add(Guid.NewGuid(), stat);
                    }
                }
            }
        }
Exemple #17
0
        internal void Set(MemoryCacheKey key, MemoryCacheEntry entry)
        {
            if (this._useInsertBlock && entry.HasUsage())
            {
                this.WaitInsertBlock();
            }
            MemoryCacheEntry entry2 = null;
            bool             flag   = false;

            lock (this._entriesLock)
            {
                if (this._disposed == 0)
                {
                    entry2 = this._entries[key] as MemoryCacheEntry;
                    if (entry2 != null)
                    {
                        entry2.State = EntryState.RemovingFromCache;
                    }
                    entry.State        = EntryState.AddingToCache;
                    flag               = true;
                    this._entries[key] = entry;
                }
            }
            CacheEntryRemovedReason removed = CacheEntryRemovedReason.Removed;

            if (entry2 != null)
            {
                if (entry2.UtcAbsExp <= DateTime.UtcNow)
                {
                    removed = CacheEntryRemovedReason.Expired;
                }
                bool delayRelease = true;
                this.RemoveFromCache(entry2, removed, delayRelease);
            }
            if (flag)
            {
                this.AddToCache(entry);
            }
            if (entry2 != null)
            {
                entry2.Release(this._cache, removed);
            }
        }
Exemple #18
0
        internal void Release(MemoryCache cache, CacheEntryRemovedReason reason)
        {
            State = EntryState.Closed;

            // Are there any cache entries that depend on this entry?
            // If so, we need to fire their dependencies.
            Dictionary <MemoryCacheEntryChangeMonitor, MemoryCacheEntryChangeMonitor> .KeyCollection deps = null;
            // clone the dependents
            lock (this)
            {
                if (_fields != null && _fields._dependents != null && _fields._dependents.Count > 0)
                {
                    deps = _fields._dependents.Keys;
                    // set to null so RemoveDependent does not attempt to access it, since we're not
                    // using a copy of the KeyCollection.
                    _fields._dependents = null;
                    Debug.Assert(_fields._dependents == null, "_fields._dependents == null");
                }
            }
            if (deps != null)
            {
                foreach (MemoryCacheEntryChangeMonitor dependent in deps)
                {
                    if (dependent != null)
                    {
                        dependent.OnCacheEntryReleased();
                    }
                }
            }

            CallCacheEntryRemovedCallback(cache, reason);

            // Dispose any dependencies
            if (_fields != null && _fields._dependencies != null)
            {
                foreach (ChangeMonitor monitor in _fields._dependencies)
                {
                    monitor.Dispose();
                }
            }
        }
        /// <summary>
        ///     Calls the <see cref="CacheEntryUpdateCallback" /> for the selected key.
        /// </summary>
        /// <param name="key">Key</param>
        /// <param name="reason">Reason why the value was removed</param>
        /// <param name="regionName">The name of the region in the InternalCache</param>
        private void CallEntryUpdates(string key,
                                      CacheEntryRemovedReason reason = CacheEntryRemovedReason.Removed,
                                      string regionName = null)
        {
            CacheEntryUpdateCallback callback;
            var contains = _cacheEntryUpdateCallbacks.TryGetValue(key + regionName, out callback);

            if (!contains)
            {
                return;
            }

            try
            {
                callback.Invoke(new CacheEntryUpdateArguments(this, reason, key, regionName));
            }
            catch (Exception e)
            {
                Logging.Write()(LogLevel.Error, "An exception occured while invoking the EntryUpdateCallbacks: {0}", e);
            }
        }
Exemple #20
0
        async void CleanupCacheItem(Task <TValue> valueTask, string textKey, CacheEntryRemovedReason reason)
        {
            await valueTask.ContinueWith(async t =>
            {
                if (t.IsFaulted)
                {
                    return;
                }

                var value = t.Result;
                await _valueRemoved(textKey, value, reason.ToString()).ConfigureAwait(false);

                var disposable = value as IDisposable;
                disposable?.Dispose();

                var asyncDisposable = value as IAsyncDisposable;
                if (asyncDisposable != null)
                {
                    await asyncDisposable.DisposeAsync().ConfigureAwait(false);
                }
            }).ConfigureAwait(false);
        }
Exemple #21
0
        public void DisposedCacheTest()
        {
            var mc = new MemoryCache("my disposed cache 1");

            mc.Add("aa", "bb", new CacheItemPolicy());
            mc.Dispose();

            Assert.Null(mc["aa"]);

            mc = new MemoryCache("my disposed cache 2");
            CacheEntryRemovedReason reason = (CacheEntryRemovedReason)1111;
            var cip = new CacheItemPolicy();

            cip.RemovedCallback = (CacheEntryRemovedArguments args) =>
            {
                reason = args.RemovedReason;
            };

            mc.Set("key", "value", cip);
            mc.Dispose();
            Assert.Equal(reason, CacheEntryRemovedReason.CacheSpecificEviction);
        }
        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);
                }
            }
        }
Exemple #23
0
		bool ExpireIfNeeded (string key, MemoryCacheEntry entry, bool needsLock = true, CacheEntryRemovedReason reason = CacheEntryRemovedReason.Expired)
		{
			bool locked = false;
			
			try {
				if (entry.IsExpired) {
					if (needsLock) {
						cache_lock.EnterWriteLock ();
						locked = true;
					}
					
					cache.Remove (key);
					perfCounters.Decrement (MemoryCachePerformanceCounters.CACHE_ENTRIES);
					entry.Removed (owner, CacheEntryRemovedReason.Expired);
					
					return true;
				}
			} finally {
				if (locked)
					cache_lock.ExitWriteLock ();
			}
			
			return false;
		}
Exemple #24
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);
         }
     }
 }
 public CacheEntryUpdateArguments(ObjectCache source, CacheEntryRemovedReason reason, string key, string regionName)
 {
     Contract.Requires(source != null);
     Contract.Requires(key != null);
 }
Exemple #26
0
 private void RootCacheItemRemoved(string key, object value, CacheEntryRemovedReason reason)
 {
     rootCacheKeyStored = false;
 }
 internal MemoryCacheEntry RemoveEntry(string key, MemoryCacheEntry entry, CacheEntryRemovedReason reason)
 {
     MemoryCacheKey key2 = new MemoryCacheKey(key);
     return this.GetStore(key2).Remove(key2, entry, reason);
 }
 public CacheEntryRemovedArguments(ObjectCache source, CacheEntryRemovedReason reason, CacheItem cacheItem)
 {
     Contract.Requires(source != null);
     Contract.Requires(cacheItem != null);
 }
Exemple #29
0
		// NOTE: this must be called with the write lock held
		void DoRemoveEntry (MemoryCacheEntry entry, bool updateLRU = true, string key = null, CacheEntryRemovedReason reason = CacheEntryRemovedReason.Removed)
		{
			if (key == null)
				key = entry.Key;

			cache.Remove (key);
			if (updateLRU)
				lru.Remove (entry);
			perfCounters.Decrement (MemoryCachePerformanceCounters.CACHE_ENTRIES);
			entry.Removed (owner, reason);
		}
Exemple #30
0
        // NOTE: this must be called with the write lock held
        void DoRemoveEntry(MemoryCacheEntry entry, bool updateLRU = true, string key = null, CacheEntryRemovedReason reason = CacheEntryRemovedReason.Removed)
        {
            if (key == null)
            {
                key = entry.Key;
            }

            cache.Remove(key);
            if (updateLRU)
            {
                lru.Remove(entry);
            }
            perfCounters.Decrement(MemoryCachePerformanceCounters.CACHE_ENTRIES);
            entry.Removed(owner, reason);
        }
Exemple #31
0
		public void Updated (MemoryCache owner, CacheEntryRemovedReason reason)
		{
			if (updateCallback == null)
				return;
			
			try {
				var args = new CacheEntryUpdateArguments (owner, reason, Key, null);
				updateCallback (args);
			} catch {
				// ignore - we don't care about the exceptions thrown inside the
				// handler
			}
		}
 private void CallCacheEntryRemovedCallback(MemoryCache cache, CacheEntryRemovedReason reason) {
     if (_callback == null) {
         return;
     }
     CacheEntryRemovedArguments args = new CacheEntryRemovedArguments(cache, reason, new CacheItem(Key, _value));
     try {
         _callback(args);
     }
     catch {
         // 
     }
 }
 static void x_CacheItemEntryRemoved(CacheItemEntryRemovedNotifier sender, CacheEntryRemovedReason reason)
 {
     sender.ExpireSeconds = 10;
 }
 internal MemoryCacheEntry Remove(MemoryCacheKey key, MemoryCacheEntry entryToRemove, CacheEntryRemovedReason reason)
 {
     MemoryCacheEntry objA = null;
     lock (this._entriesLock)
     {
         if (this._disposed == 0)
         {
             objA = this._entries[key] as MemoryCacheEntry;
             if ((entryToRemove == null) || object.ReferenceEquals(objA, entryToRemove))
             {
                 if (objA != null)
                 {
                     objA.State = EntryState.RemovingFromCache;
                 }
                 this._entries.Remove(key);
             }
             else
             {
                 objA = null;
             }
         }
     }
     this.RemoveFromCache(objA, reason, false);
     return objA;
 }
Exemple #35
0
		private void RootCacheItemRemoved(string key, object value, CacheEntryRemovedReason reason)
		{
			rootCacheKeyStored = false;
		}
 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);
         }
     }
 }
 public CacheEntryRemovedArguments(ObjectCache source, CacheEntryRemovedReason reason, CacheItem cacheItem)
 {
     Contract.Requires(source != null);
     Contract.Requires(cacheItem != null);
 }
        internal MemoryCacheEntry Remove(MemoryCacheKey key, MemoryCacheEntry entryToRemove, CacheEntryRemovedReason reason)
        {
            MemoryCacheEntry entry = null;

            lock (_entriesLock) {
                if (_disposed == 0)
                {
                    // get current entry
                    entry = _entries[key] as MemoryCacheEntry;
                    // remove if it matches the entry to be removed (but always remove if entryToRemove is null)
                    if (entryToRemove == null || Object.ReferenceEquals(entry, entryToRemove))
                    {
                        // Dev10 865887: MemoryCache.Remove("\ue637\ud22a\u3e17") causes NullReferenceEx
                        if (entry != null)
                        {
                            entry.State = EntryState.RemovingFromCache;
                            _entries.Remove(key);
                        }
                    }
                    else
                    {
                        entry = null;
                    }
                }
            }
            // release outside of lock
            RemoveFromCache(entry, reason);
            return(entry);
        }
 internal MemoryCacheEntry Remove(MemoryCacheKey key, MemoryCacheEntry entryToRemove, CacheEntryRemovedReason reason) {
     MemoryCacheEntry entry = null;
     lock (_entriesLock) {
         if (_disposed == 0) {
             // get current entry
             entry = _entries[key] as MemoryCacheEntry;
             // remove if it matches the entry to be removed (but always remove if entryToRemove is null)
             if (entryToRemove == null || Object.ReferenceEquals(entry, entryToRemove)) {
                 // Dev10 865887: MemoryCache.Remove("\ue637\ud22a\u3e17") causes NullReferenceEx
                 if (entry != null) {
                     entry.State = EntryState.RemovingFromCache;
                     _entries.Remove(key);
                 }
             }
             else {
                 entry = null;
             }
         }
     }
     // release outside of lock
     RemoveFromCache(entry, reason);
     return entry;
 }
Exemple #40
0
		public void Removed (MemoryCache owner, CacheEntryRemovedReason reason)
		{
			if (removedCallback == null) {
				Disabled = true;
				return;
			}
			
			try {
				removedCallback (new CacheEntryRemovedArguments (owner, reason, new CacheItem (Key, Value)));
			} catch {
				// ignore - we don't care about the exceptions thrown inside the
				// handler
			} finally {
				Disabled = true;
			}
		}
        internal MemoryCacheEntry RemoveEntry(string key, MemoryCacheEntry entry, CacheEntryRemovedReason reason)
        {
            MemoryCacheKey key2 = new MemoryCacheKey(key);

            return(this.GetStore(key2).Remove(key2, entry, reason));
        }
 internal void Release(MemoryCache cache, CacheEntryRemovedReason reason)
 {
     this.State = EntryState.Closed;
     Dictionary<MemoryCacheEntryChangeMonitor, MemoryCacheEntryChangeMonitor>.KeyCollection keys = null;
     lock (this)
     {
         if (((this._fields != null) && (this._fields._dependents != null)) && (this._fields._dependents.Count > 0))
         {
             keys = this._fields._dependents.Keys;
             this._fields._dependents = null;
         }
     }
     if (keys != null)
     {
         foreach (MemoryCacheEntryChangeMonitor monitor in keys)
         {
             if (monitor != null)
             {
                 monitor.OnCacheEntryReleased();
             }
         }
     }
     this.CallCacheEntryRemovedCallback(cache, reason);
     if ((this._fields != null) && (this._fields._dependencies != null))
     {
         foreach (ChangeMonitor monitor2 in this._fields._dependencies)
         {
             monitor2.Dispose();
         }
     }
 }
Exemple #43
0
 internal MemoryCacheEntry RemoveEntry(string key, MemoryCacheEntry entry, CacheEntryRemovedReason reason) {
     MemoryCacheKey cacheKey = new MemoryCacheKey(key);
     MemoryCacheStore store = GetStore(cacheKey);
     return store.Remove(cacheKey, entry, reason);
 }
Exemple #44
0
        bool ExpireIfNeeded(string key, MemoryCacheEntry entry, bool needsLock = true, CacheEntryRemovedReason reason = CacheEntryRemovedReason.Expired)
        {
            bool locked = false;

            try {
                if (entry.IsExpired)
                {
                    if (needsLock)
                    {
                        cache_lock.EnterWriteLock();
                        locked = true;
                    }

                    cache.Remove(key);
                    perfCounters.Decrement(MemoryCachePerformanceCounters.CACHE_ENTRIES);
                    entry.Removed(owner, CacheEntryRemovedReason.Expired);

                    return(true);
                }
            } finally {
                if (locked)
                {
                    cache_lock.ExitWriteLock();
                }
            }

            return(false);
        }
Exemple #45
0
 public CacheEntryUpdateArguments(ObjectCache source, CacheEntryRemovedReason reason, string key, string regionName)
 {
     Contract.Requires(source != null);
     Contract.Requires(key != null);
 }
 public void ConfigurationChanged(string settingsPath, CacheEntryRemovedReason removedReason)
 {
     this.logger.Log(
         LogLevel.Information,
         "Configuration file '{0}' changed {1}",
         settingsPath,
         removedReason);
 }
Exemple #47
0
        internal MemoryCacheEntry Remove(MemoryCacheKey key, MemoryCacheEntry entryToRemove, CacheEntryRemovedReason reason)
        {
            MemoryCacheEntry objA = null;

            lock (this._entriesLock)
            {
                if (this._disposed == 0)
                {
                    objA = this._entries[key] as MemoryCacheEntry;
                    if ((entryToRemove == null) || object.ReferenceEquals(objA, entryToRemove))
                    {
                        if (objA != null)
                        {
                            objA.State = EntryState.RemovingFromCache;
                        }
                        this._entries.Remove(key);
                    }
                    else
                    {
                        objA = null;
                    }
                }
            }
            this.RemoveFromCache(objA, reason, false);
            return(objA);
        }
        internal void Release(MemoryCache cache, CacheEntryRemovedReason reason) {
            State = EntryState.Closed;

            // Are there any cache entries that depend on this entry?
            // If so, we need to fire their dependencies.
            Dictionary<MemoryCacheEntryChangeMonitor, MemoryCacheEntryChangeMonitor>.KeyCollection deps = null;
            // clone the dependents
            lock (this) {
                if (_fields != null && _fields._dependents != null && _fields._dependents.Count > 0) {
                    deps = _fields._dependents.Keys;
                    // set to null so RemoveDependent does not attempt to access it, since we're not
                    // using a copy of the KeyCollection.
                    _fields._dependents = null;
                    Dbg.Assert(_fields._dependents == null, "_fields._dependents == null");
                }
            }
            if (deps != null) {
                foreach (MemoryCacheEntryChangeMonitor dependent in deps) {
                    if (dependent != null) {
                        dependent.OnCacheEntryReleased();
                    }
                }
            }

            CallCacheEntryRemovedCallback(cache, reason);

            // Dispose any dependencies
            if (_fields != null && _fields._dependencies != null) {
                foreach (ChangeMonitor monitor in _fields._dependencies) {
                    monitor.Dispose();
                }
            }
        }
        static void x_CacheItemEntryRemoved(CacheItemEntryRemovedNotifier sender, CacheEntryRemovedReason reason)
        {

            sender.ExpireSeconds = 10;
        }