private CacheStatisticItem Convert(CacheStatistic en, string methodName) { CacheStatisticItem item = new CacheStatisticItem(); item.Method = methodName; item.CacheName = en.CacheName; item.HitCount = en.HitCount; item.TotalExecuteTimes = en.TotalExecuteTimes; item.HitRate = Math.Round((double)item.HitCount / (double)item.TotalExecuteTimes, 3); item.GroupName = en.GroupName; if (item.GroupName == null) { item.GroupName = string.Empty; item.ItemCount = 1; item.Keys = item.Method; } else { ICache cache = CacheFactory.GetInstance(item.CacheName); List <string> keys = cache.GetKeysByGroup(item.GroupName); item.ItemCount = keys.Count; item.Keys = string.Join("; ", keys.ToArray()); } return(item); }
public CacheStatisticItem GetStatisticByMethod(string methodName) { CacheStatistic en = CacheStatisticManager.GetStatisticByMethod(methodName); if (en != null) { return(Convert(en, methodName)); } return(null); }
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); } }