One of my legacy application heavily used MemoryCache, therefore I was trying to know how memory cache internally works but now I'm totally confused after some below experiments. Please help me to resolve my confusion.
Question 1 how to check system cache memory? I used below command on command prompt but not able to understand result
wmic cpu get L2CacheSize, L2CacheSpeed, L3CacheSize, L3CacheSpeed
Result
L2CacheSize L2CacheSpeed L3CacheSize L3CacheSpeed
512 4096 0
Question 2 I used C# code to check cache memory size and available cache memory size, therefore I write below code. why program 2 not throwing error? & how to check available cache memory size? (program 3 throwing error)
Program 1:
var memeoryCache = new MemoryCache("CacheItems");
Console.WriteLine(memeoryCache.CacheMemoryLimit);
Console.WriteLine(memeoryCache.PhysicalMemoryLimit);
Result
838860800//Get amount of memory on the computer, in byte, that can be used by cache
99//Gets the percentage of physical memory that the cache can use.
Program2:
var memeoryCache = new MemoryCache("CacheItems");
Console.WriteLine("***** Memory Cache Test *****");
Console.WriteLine(memeoryCache.CacheMemoryLimit);
Console.WriteLine(memeoryCache.PhysicalMemoryLimit);
var bytearray = new byte[838860800];
memeoryCache.Add("Test", bytearray, DateTimeOffset.Now.AddMinutes(10));
var bytearray2 = new byte[100000];
memeoryCache.Add("Test2", bytearray2, DateTimeOffset.Now.AddMinutes(10));
Console.ReadLine();
var test = memeoryCache.Get("Test");
var test2 = memeoryCache.Get("Test2");
Console.ReadLine();
Progma3:
var memeoryCache = new MemoryCache("CacheItems");
Console.WriteLine("***** Memory Cache Test *****");
Console.WriteLine(memeoryCache.CacheMemoryLimit);
Console.WriteLine(memeoryCache.PhysicalMemoryLimit);
var bytearray = new byte[838860800];
memeoryCache.Add("Test", bytearray, DateTimeOffset.Now.AddMinutes(10));
var bytearray2 = new byte[838860800];
memeoryCache.Add("Test2", bytearray2, DateTimeOffset.Now.AddMinutes(10));
Console.ReadLine();
var test = memeoryCache.Get("Test");
var test2 = memeoryCache.Get("Test2");
Console.ReadLine();
Result:
An unhandled exception of type 'System.OutOfMemoryException' occurred in MemoryCacheTest.exe
Question 3 How to check what is stored in cache memory? or Which application data stored in cache memory?