예제 #1
0
        /// <summary>
        /// Populates the drop down list with an ordered list of cache type names.
        /// The selected item is used for the button to clear all the cache of
        /// that type.
        /// </summary>
        protected void PopulateCacheTypes()
        {
            ddlCacheTypes.Items.Clear();
            var entityCacheTypes = RockCache.GetAllModelCacheTypes();

            foreach (var entityCacheType in entityCacheTypes.OrderBy(s => s.Name))
            {
                ddlCacheTypes.Items.Add(new ListItem(entityCacheType.Name, entityCacheType.Name));
            }
        }
예제 #2
0
        private void GetCacheData()
        {
            var totalCacheSize = 0;

            // Determine the size of the object cache
            var objectCacheKeys = RockCache.ObjectCacheKeyReferences;

            var objectCacheSize = 0;

            foreach (var objectCacheKey in objectCacheKeys)
            {
                var cacheItem = RockCache.Get(objectCacheKey.Key, objectCacheKey.Region);
                if (cacheItem.IsNotNull())
                {
                    objectCacheSize += cacheItem.ToJson().Length;
                }
            }

            totalCacheSize += objectCacheSize;

            // Output object cache size
            lOutput.Text = string.Format("Object Cache: {0:n0} KB", objectCacheSize / 1024);

            // Determine the size of the string cache
            var stringCacheKeys = RockCache.StringCacheKeyReferences;

            var stringCacheSize = 0;

            foreach (var stringCacheKey in stringCacheKeys)
            {
                // Cache tags are in an empty region. Calls without a region throw an exception
                if (stringCacheKey.Region.IsNotNullOrWhiteSpace())
                {
                    var value = RockCacheManager <List <string> > .Instance.Get(stringCacheKey.Key, stringCacheKey.Region);

                    if (value.IsNotNull())
                    {
                        stringCacheSize += value.ToJson().Length;
                    }
                }
                else
                {
                    var cacheItem = RockCache.Get(stringCacheKey.Key, stringCacheKey.Region);
                    if (cacheItem.IsNotNull())
                    {
                        stringCacheSize += cacheItem.ToJson().Length;
                    }
                }
            }

            totalCacheSize += stringCacheSize;

            // Output object cache size
            lOutput.Text += string.Format("<br>String Cache: {0:n0} KB", stringCacheSize / 1024);


            lOutput.Text += "<hr>";
            lOutput.Text += "<h4>Model Cache Sizes</h4>";

            // Get type for the generic model type cache
            var cacheModelType = typeof(ModelCache <,>);

            // Get a listing of all cached models
            var cachedModels = RockCache.GetAllModelCacheTypes().OrderBy(a => a.Name).ToList();

            foreach (var cachedModel in cachedModels)
            {
                //Type rockCacheManagerType = typeof( RockCacheManager<> ).MakeGenericType( new Type[] { cachedModel } );

                if (cachedModel.BaseType.Name == cacheModelType.Name)
                {
                    // this is an entity cache model
                    try
                    {
                        var methodInfo = cachedModel.BaseType.BaseType.GetMethods().Where(m => m.Name == "All").Where(m => m.GetParameters().Length == 0).FirstOrDefault();
                        if (methodInfo != null)
                        {
                            var length = methodInfo.Invoke(null, null).ToJson().Length;
                            lOutput.Text += string.Format("<br>{0} - {1:n0} KB", cachedModel.Name, length / 1024);

                            totalCacheSize += length;
                        }
                    }
                    catch (Exception) { };
                }
            }

            lOutput.Text += string.Format("<p><p><strong>Total Cache Size: {0:n0} KB</strong>", totalCacheSize / 1024);
        }