I am using the memorycache in .net 4 with multiple named instances of caches. I was wondering is there was a way to list all cache instances currently in memory?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There is no way to get cache instances currently in memory without having references to them.
So the solution is to make a list yourself and keep track that way.
Then just add to that list when a new
MemoryCacheobject is created (and remove when it is destroyed).MemoryCache is not anything magical, you can think of it as just an improvement upon using:
or a
hashtableinstead.The benefits of MemoryCache is that you get object expiry (TTL), more control on removing less recently used items when the cache nears some storage limits (access priority queue).
So if you want to know what MemoryCache instances are currently in memory, then you need to reference them, I am pretty sure that you cannot access a memory cache for a different process hence only MemoryCaches you create will exist.