Ejemplo n.º 1
0
        /// <summary>
        /// Invokes the refresh action on a thread pool thread
        /// </summary>
        /// <param name="removedCacheItem">Cache item being removed. Must never be null.</param>
        /// <param name="removalReason">The reason the item was removed.</param>
        /// <param name="instrumentationProvider">The instrumentation provider.</param>
        public static void InvokeRefreshAction(CacheItem removedCacheItem, CacheItemRemovedReason removalReason, ICachingInstrumentationProvider instrumentationProvider)
        {
            if (removedCacheItem == null)
            {
                throw new ArgumentNullException("removedCacheItem");
            }
            if (instrumentationProvider == null)
            {
                throw new ArgumentNullException("instrumentationProvider");
            }

            if (removedCacheItem.RefreshAction == null)
            {
                return;
            }

            try
            {
                RefreshActionData refreshActionData =
                    new RefreshActionData(removedCacheItem.RefreshAction, removedCacheItem.Key, removedCacheItem.Value, removalReason, instrumentationProvider);
                refreshActionData.InvokeOnThreadPoolThread();
            }
            catch (Exception e)
            {
                instrumentationProvider.FireCacheFailed(Resources.FailureToSpawnUserSpecifiedRefreshAction, e);
            }
        }
 internal void BackgroundWork(Action work)
 {
     try
     {
         lock (scavengeExpireLock)
         {
             work();
         }
     }
     catch (Exception e)
     {
         instrumentationProvider.FireCacheFailed(Resources.BackgroundSchedulerProducerConsumerQueueFailure, e);
     }
 }
Ejemplo n.º 3
0
        private bool RemoveItemFromCache(CacheItem itemToRemove)
        {
            lock (itemToRemove)
            {
                if (itemToRemove.EligibleForScavenging)
                {
                    try
                    {
                        cacheOperations.RemoveItemFromCache(itemToRemove.Key, CacheItemRemovedReason.Scavenged);
                        return(true);
                    }
                    catch (Exception e)
                    {
                        instrumentationProvider.FireCacheFailed(Resources.FailureToRemoveCacheItemInBackground, e);
                    }
                }
            }

            return(false);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Вызов рефреша в нити
        /// </summary>
        /// <param name="removedCacheItem">Удаляемый кэш-элемент. Не null.</param>
        /// <param name="removalReason">Причина удаления.</param>
        /// <param name="instrumentationProvider"></param>	
        public static void InvokeRefreshAction(CacheItem removedCacheItem, CacheItemRemovedReason removalReason, ICachingInstrumentationProvider instrumentationProvider)
        {
            if (removedCacheItem == null) throw new ArgumentNullException("removedCacheItem");
            if (instrumentationProvider == null) throw new ArgumentNullException("instrumentationProvider");

            if (removedCacheItem.RefreshAction == null)
            {
                return;
            }

            try
            {
                var refreshActionData = new RefreshActionData(removedCacheItem.RefreshAction, removedCacheItem.Key, removedCacheItem.Value, removalReason, instrumentationProvider);
                refreshActionData.InvokeOnThreadPoolThread();
            }
            catch (Exception e)
            {
                instrumentationProvider.FireCacheFailed(Resources.FailureToSpawnUserSpecifiedRefreshAction, e);
            }
        }
Ejemplo n.º 5
0
        private bool RemoveItemFromCache(CacheItem itemToRemove)
        {
            bool expired = false;

            lock (itemToRemove)
            {
                if (itemToRemove.WillBeExpired)
                {
                    try
                    {
                        expired = true;
                        cacheOperations.RemoveItemFromCache(itemToRemove.Key, CacheItemRemovedReason.Expired);
                    }
                    catch (Exception e)
                    {
                        instrumentationProvider.FireCacheFailed(Resources.FailureToRemoveCacheItemInBackground, e);
                    }
                }
            }

            return(expired);
        }