示例#1
0
        public ActionResult GetCacheInfo()
        {
            var memoryCache = MemoryCache.Default;

            string name     = memoryCache.Name;
            long   count    = memoryCache.GetCount();
            int    hashCode = memoryCache.GetHashCode();

            var model = new CacheViewModel()
            {
                Name        = name,
                Count       = count,
                HashCode    = hashCode,
                CachedItems = new List <CachedItem>()
            };

            Debug.WriteLine(string.Format("Cache name: {0}", name));
            Debug.WriteLine(string.Format("Antal cachade objekt: {0}", count));
            Debug.WriteLine(string.Format("Cache hash code: {0}", hashCode));
            Debug.WriteLine("");

            Debug.WriteLine("Cachens innehåll");

            var cacheEnumberable = (IEnumerable)memoryCache;

            foreach (DictionaryEntry item in cacheEnumberable)
            {
                IList cachedList = item.Value as IList;

                var cachedItem = new CachedItem
                {
                    CacheKey     = item.Key.ToString(),
                    CachedObject = item.Value,
                    CachedType   = item.Value.GetType(),
                    ListCount    = cachedList == null ? (int?)null : cachedList.Count
                };
                model.CachedItems.Add(cachedItem);

                Debug.WriteLine(string.Format("Cachenyckel: {0}", cachedItem.CacheKey));
                Debug.WriteLine(string.Format("Cachad type: {0}", cachedItem.CachedType));

                if (cachedList != null)
                {
                    Debug.WriteLine("Cachat objekt är en lista");
                    Debug.WriteLine(string.Format("Antal objekt i cachad lista: {0}", cachedItem.ListCount));

                    foreach (var listItem in cachedList)
                    {
                        Debug.WriteLine(String.Format("\t{0}", listItem));
                    }
                }
                Debug.WriteLine("");
            }

            return(View(model));
        }
示例#2
0
        public ActionResult GetCacheInfo()
        {
            var memoryCache = MemoryCache.Default;

            string name     = memoryCache.Name;
            long   count    = memoryCache.GetCount();
            int    hashCode = memoryCache.GetHashCode();

            var model = new CacheViewModel()
            {
                Name        = name,
                Count       = count,
                HashCode    = hashCode,
                CachedItems = new List <CachedItem>()
            };

            Debug.WriteLine($"Cache name: {name}");
            Debug.WriteLine($"Cache count objects: {count}");
            Debug.WriteLine($"Cache hash code: {hashCode}");
            Debug.WriteLine("");

            Debug.WriteLine("Cache content");

            var cacheEnumberable = (IEnumerable)memoryCache;

            foreach (DictionaryEntry item in cacheEnumberable)
            {
                IList cachedList = item.Value as IList;

                var cachedItem = new CachedItem
                {
                    CacheKey     = item.Key.ToString(),
                    CachedObject = item.Value,
                    CachedType   = item.Value.GetType(),
                    ListCount    = cachedList?.Count
                };
                model.CachedItems.Add(cachedItem);

                Debug.WriteLine($"Cached key: {cachedItem.CacheKey}");
                Debug.WriteLine($"Cached type: {cachedItem.CachedType}");

                if (cachedList != null)
                {
                    Debug.WriteLine("Object cashed is a list");
                    Debug.WriteLine($"Items in cached list count: {cachedItem.ListCount}");

                    foreach (var listItem in cachedList)
                    {
                        Debug.WriteLine($"\t{listItem}");
                    }
                }
                Debug.WriteLine("");
            }

            return(View(model));
        }