Exemplo n.º 1
0
        /// <summary>
        /// Computes and displays a summary of cache statistics.
        /// </summary>
        protected void PopulateCacheStatistics()
        {
            long hits   = 0;
            long misses = 0;
            long adds   = 0;
            long gets   = 0;
            long clears = 0;

            var cacheItemStatistics = new List <CacheItemStatistics>();

            if (ddlCacheTypes.SelectedValue == "all")
            {
                cacheItemStatistics = RockCache.GetAllStatistics().OrderBy(s => s.Name).ToList();
            }
            else
            {
                cacheItemStatistics.Add(RockCache.GetStatisticsForType(ddlCacheTypes.SelectedValue));
            }

            foreach (CacheItemStatistics cacheItemStat in cacheItemStatistics)
            {
                foreach (CacheHandleStatistics cacheHandleStat in cacheItemStat.HandleStats)
                {
                    hits   += cacheHandleStat.Stats.Where(s => s.CounterType.ConvertToString().ToLower() == "hits").Select(s => s.Count).FirstOrDefault();
                    misses += cacheHandleStat.Stats.Where(s => s.CounterType.ConvertToString().ToLower() == "misses").Select(s => s.Count).FirstOrDefault();
                    adds   += cacheHandleStat.Stats.Where(s => s.CounterType.ConvertToString().ToLower() == "add calls").Select(s => s.Count).FirstOrDefault();
                    adds   += cacheHandleStat.Stats.Where(s => s.CounterType.ConvertToString().ToLower() == "put calls").Select(s => s.Count).FirstOrDefault();
                    gets   += cacheHandleStat.Stats.Where(s => s.CounterType.ConvertToString().ToLower() == "get calls").Select(s => s.Count).FirstOrDefault();
                    clears += cacheHandleStat.Stats.Where(s => s.CounterType.ConvertToString().ToLower() == "clear calls").Select(s => s.Count).FirstOrDefault();
                    clears += cacheHandleStat.Stats.Where(s => s.CounterType.ConvertToString().ToLower() == "clear region calls").Select(s => s.Count).FirstOrDefault();
                }
            }

            string htmlText = "<tr><td>Hits</td><td>{0:N0}</td><tr><td>Misses</td><td>{1:N0}</td></tr><tr><td>Adds</td><td>{2:N0}</td></tr><tr><td>Gets</td><td>{3:N0}</td></tr><tr><td>Clears</td><td>{4:N0}</td></tr>";

            lCacheStatistics.Text = string.Format(htmlText, hits, misses, adds, gets, clears);
        }