Exemple #1
0
        /// <summary>
        /// Gets the statistics for the cache instance.
        /// </summary>
        /// <returns></returns>
        public CacheItemStatistics GetStatistics()
        {
            //type.IsGenericType && type.GenericTypeArguments[0] == typeof( Rock.Model.Person );
            var type = typeof(T);

            string name = type.Name;

            if (type.IsGenericType && type.GenericTypeArguments[0] != null)
            {
                name = type.GenericTypeArguments[0].ToString();
            }

            var cacheStatistics = new CacheItemStatistics(name);

            //var cacheStatistics = new CacheItemStatistics( typeof( T ).Name );

            foreach (var handle in Cache.CacheHandles)
            {
                var handleStatistics = new CacheHandleStatistics(handle.Configuration.HandleType.Name);
                cacheStatistics.HandleStats.Add(handleStatistics);

                var stats = handle.Stats;
                foreach (CacheStatsCounterType statType in Enum.GetValues(typeof(CacheStatsCounterType)))
                {
                    handleStatistics.Stats.Add(new CacheStatistic(statType, stats.GetStatistic(statType)));
                }
            }

            return(cacheStatistics);
        }
Exemple #2
0
        /// <summary>
        /// Gets the statistics for the given type.
        /// </summary>
        /// <param name="cacheType">Type of the cache.</param>
        /// <returns></returns>
        public static CacheItemStatistics GetStatisticsForType(Type cacheType)
        {
            var cacheStats = new CacheItemStatistics(string.Empty);

            if (_allManagers == null)
            {
                return(cacheStats);
            }

            Type rockCacheManagerType = typeof(RockCacheManager <>).MakeGenericType(new Type[] { cacheType });

            foreach (var manager in _allManagers)
            {
                if (manager.GetType() == rockCacheManagerType)
                {
                    cacheStats = manager.GetStatistics();
                    break;
                }
            }

            return(cacheStats);
        }
Exemple #3
0
        /// <summary>
        /// Gets the cache statistics for a cache type
        /// </summary>
        /// <param name="cacheTypeName">Name of the cache type.</param>
        /// <returns></returns>
        public static CacheItemStatistics GetStatForSystemType(string cacheTypeName)
        {
            var cacheStats = new CacheItemStatistics(string.Empty);

            if (_allManagers == null)
            {
                return(cacheStats);
            }

            if (cacheTypeName == "System.String")
            {
                return(RockCacheManager <List <string> > .Instance.GetStatistics());
            }
            else if (cacheTypeName == "System.Int32")
            {
                return(RockCacheManager <int?> .Instance.GetStatistics());
            }
            else if (cacheTypeName == "Object")
            {
                return(RockCacheManager <object> .Instance.GetStatistics());
            }

            return(cacheStats);
        }