Exemple #1
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 #2
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);
        }
		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;
		}
		// 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);
		}