コード例 #1
0
        public override object GetData(ITabContext context)
        {
            var cacheModel = new CacheModel();

            cacheModel.Configuration.EffectivePercentagePhysicalMemoryLimit = HttpRuntime.Cache.EffectivePercentagePhysicalMemoryLimit;
            cacheModel.Configuration.EffectivePrivateBytesLimit             = HttpRuntime.Cache.EffectivePrivateBytesLimit;

            var list = HttpRuntime.Cache.Cast <DictionaryEntry>().ToList();

            foreach (var item in list)
            {
                try
                {
                    var cacheEntry = MethodInfoCacheGet.Invoke(HttpRuntime.Cache, new object[] { item.Key, 1 });

                    var cacheItemModel = new CacheItemModel();
                    cacheItemModel.Key               = item.Key.ToString();
                    cacheItemModel.Value             = Serialization.GetValueSafe(item.Value);
                    cacheItemModel.CreatedOn         = GetCacheProperty(ProcessInfoUtcCreated, cacheEntry) as DateTime?;
                    cacheItemModel.ExpiresOn         = GetCacheProperty(ProcessInfoUtcExpires, cacheEntry) as DateTime?;
                    cacheItemModel.SlidingExpiration = GetCacheProperty(ProcessInfoSlidingExpiration, cacheEntry) as TimeSpan?;

                    cacheModel.CacheItems.Add(cacheItemModel);
                }
                catch (Exception)
                {
                    return(false);
                }
            }

            return(cacheModel);
        }
コード例 #2
0
ファイル: Cache.cs プロジェクト: jnfsmile/Glimpse
        public override object GetData(ITabContext context)
        {
            var cacheModel      = new CacheModel();
            var cacheEnumerator = HttpRuntime.Cache.GetEnumerator();

            cacheModel.Configuration.EffectivePercentagePhysicalMemoryLimit = HttpRuntime.Cache.EffectivePercentagePhysicalMemoryLimit;
            cacheModel.Configuration.EffectivePrivateBytesLimit             = HttpRuntime.Cache.EffectivePrivateBytesLimit;

            while (cacheEnumerator.MoveNext())
            {
                var currentCacheEntry = cacheEnumerator.Entry;

                CacheItemModel cacheItemModel = null;
                if (TryGetCacheItemModel(currentCacheEntry, out cacheItemModel))
                {
                    cacheModel.CacheItems.Add(cacheItemModel);
                }
            }

            return(cacheModel);
        }
コード例 #3
0
ファイル: Cache.cs プロジェクト: jnfsmile/Glimpse
        private bool TryGetCacheItemModel(DictionaryEntry currentCacheEntry, out CacheItemModel cacheItemModel)
        {
            cacheItemModel = new CacheItemModel();
            object cacheEntry;

            try
            {
                cacheEntry = MethodInfoCacheGet.Invoke(HttpRuntime.Cache, new object[] { currentCacheEntry.Key, 1 });

                cacheItemModel.Key       = currentCacheEntry.Key.ToString();
                cacheItemModel.Value     = Serialization.GetValueSafe(currentCacheEntry.Value);
                cacheItemModel.CreatedOn = GetCacheProperty(ProcessInfoUtcCreated, cacheEntry) as DateTime?;
                cacheItemModel.ExpiresOn = GetCacheProperty(ProcessInfoUtcExpires, cacheEntry) as DateTime?;

                cacheItemModel.SlidingExpiration = GetCacheProperty(ProcessInfoSlidingExpiration, cacheEntry) as TimeSpan?;
            }
            catch (Exception)
            {
                return(false);
            }

            return(true);
        }
コード例 #4
0
        private IEnumerable <CacheItemModel> GetCacheItems()
        {
            var list = new List <CacheItemModel>();

            var cache = MemoryCache.Default;

            var storesField = typeof(MemoryCache).GetField("_stores", BindingFlags.NonPublic | BindingFlags.Instance);

            if (storesField != null)
            {
                var stores = (object[])storesField.GetValue(cache);

                if (stores != null)
                {
                    // MemoryCacheStore
                    foreach (var store in stores)
                    {
                        var entriesField = store.GetType().GetField("_entries", BindingFlags.NonPublic | BindingFlags.Instance);

                        if (entriesField != null)
                        {
                            var entries = (Hashtable)entriesField.GetValue(store);

                            if (entries != null)
                            {
                                foreach (var entry in entries.Cast <DictionaryEntry>().ToList())
                                {
                                    var cacheItem = new CacheItemModel();

                                    // MemoryCacheKey
                                    var keyProp = entry.Key.GetType().GetProperty("Key", BindingFlags.NonPublic | BindingFlags.Instance);

                                    if (keyProp != null)
                                    {
                                        var entryKey = keyProp.GetValue(entry.Value);

                                        if (entryKey != null)
                                        {
                                            cacheItem.Key = entryKey.ToString();
                                        }
                                    }

                                    // MemoryCacheEntry
                                    var valueProp = entry.Value.GetType().GetProperty("Value", BindingFlags.NonPublic | BindingFlags.Instance);

                                    if (valueProp != null)
                                    {
                                        var entryValue = valueProp.GetValue(entry.Value);

                                        if (entryValue != null)
                                        {
                                            // type
                                            if (entryValue is IDictionary)
                                            {
                                                cacheItem.Type  = "Dictionary";
                                                cacheItem.Count = ((IDictionary)entryValue).Count;
                                            }
                                            else if (entryValue is IList)
                                            {
                                                cacheItem.Type  = "List";
                                                cacheItem.Count = ((IList)entryValue).Count;
                                            }
                                            else
                                            {
                                                cacheItem.Type = entryValue.GetType().Name;
                                            }

                                            // value
                                            cacheItem.Value = JsonConvert.SerializeObject(entryValue, Formatting.Indented);

                                            // size
                                            int size = 0;

                                            if (entryValue is IEnumerable)
                                            {
                                                foreach (var item in ((IEnumerable)entryValue))
                                                {
                                                    size += GetObjectSize(item);
                                                }
                                            }
                                            else
                                            {
                                                size = GetObjectSize(entryValue);
                                            }

                                            cacheItem.Size = size;
                                        }
                                    }

                                    var utcAbsExpProp = entry.Value.GetType().GetProperty("UtcAbsExp", BindingFlags.NonPublic | BindingFlags.Instance);

                                    if (utcAbsExpProp != null)
                                    {
                                        var entryExpiry = utcAbsExpProp.GetValue(entry.Value);

                                        if (entryExpiry != null)
                                        {
                                            cacheItem.ExpiryDate = (DateTime)entryExpiry;
                                        }
                                    }

                                    if (cacheItem.Key != null && cacheItem.Value != null)
                                    {
                                        list.Add(cacheItem);
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return(list);
        }