Esempio n. 1
0
        /// <devdoc>
        /// There may still be thread safety issues in this class with respect to expirations
        /// and scavenging, but I really doubt that either of those will be happening while
        /// a Flush is in progress. It seems that the most likely scenario for a flush
        /// to be called is at the very start of a program, or when absolutely nothing else
        /// is going on. Calling flush in the middle of an application would seem to be
        /// an "interesting" thing to do in normal circumstances.
        /// </devdoc>
        public void Flush()
        {
RestartFlushAlgorithm:
            lock (inMemoryCache.SyncRoot)
            {
                foreach (string key in inMemoryCache.Keys)
                {
                    bool      lockWasSuccessful = false;
                    CacheItem itemToRemove      = (CacheItem)inMemoryCache[key];
                    try
                    {
                        if (lockWasSuccessful = Monitor.TryEnter(itemToRemove))
                        {
                            itemToRemove.TouchedByUserAction(true);
                        }
                        else
                        {
                            goto RestartFlushAlgorithm;
                        }
                    }
                    finally
                    {
                        if (lockWasSuccessful)
                        {
                            Monitor.Exit(itemToRemove);
                        }
                    }
                }

                int countBeforeFlushing = inMemoryCache.Count;

                backingStore.Flush();
                inMemoryCache.Clear();

                CachingServiceItemTurnoverEvent.FireRemoveItems(countBeforeFlushing);
                CachingServiceItemTurnoverEvent.SetItemsTotal(0);
                CachingServiceCacheFlushedEvent.FireEvent();
            }
        }
Esempio n. 2
0
 private void FireCachingServiceCacheFlushedEvent()
 {
     CachingServiceCacheFlushedEvent.FireEvent();
 }