private static void Execute(MethodBase method, bool isHit, string cacheName, string group)
        {
            string         methodName        = GetKey(method);
            CacheStatistic statistic         = null;
            bool           lockWasSuccessful = false;

            do
            {
                lock (s_SyncObj)
                {
                    if (!s_CacheStatistic.ContainsKey(methodName))
                    {
                        statistic = new CacheStatistic(cacheName, group);
                        s_CacheStatistic.Add(methodName, statistic);
                    }
                    else
                    {
                        statistic = s_CacheStatistic[methodName];
                    }
                    lockWasSuccessful = Monitor.TryEnter(statistic);
                }
                if (lockWasSuccessful == false)
                {
                    Thread.Sleep(0);
                }
            }while (lockWasSuccessful == false);
            try
            {
                if (isHit)
                {
                    statistic.Hit();
                }
                else
                {
                    statistic.NotHit();
                }
            }
            finally
            {
                Monitor.Exit(statistic);
            }
        }
Ejemplo n.º 2
0
 private static void Execute(MethodBase method, bool isHit, string cacheName, string group)
 {
     string methodName = GetKey(method);
     CacheStatistic statistic = null;
     bool lockWasSuccessful = false;
     do
     {
         lock (s_SyncObj)
         {
             if (!s_CacheStatistic.ContainsKey(methodName))
             {
                 statistic = new CacheStatistic(cacheName, group);
                 s_CacheStatistic.Add(methodName, statistic);
             }
             else
             {
                 statistic = s_CacheStatistic[methodName];
             }
             lockWasSuccessful = Monitor.TryEnter(statistic);
         }
         if (lockWasSuccessful == false)
         {
             Thread.Sleep(0);
         }
     }
     while (lockWasSuccessful == false);
     try
     {
         if (isHit)
         {
             statistic.Hit();
         }
         else
         {
             statistic.NotHit();
         }
     }
     finally
     {
         Monitor.Exit(statistic);
     }
 }