예제 #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);
        }
예제 #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);
        }
예제 #3
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;
		}
예제 #4
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);
		}