I want to retrieve all the cache objects that are added using MemoryCache.
I tried the below but it is not retrieving them
System.Web.HttpContext.Current.Cache.GetEnumerator();
System.Web.HttpRuntime.Cache.GetEnumerator();
Note: Retreive all means not just what i know and created, i mean every cache object that gets created in the application.
In-Memory Cache is used for when you want to implement cache in a single process. When the process dies, the cache dies with it. If you're running the same process on several servers, you will have a separate cache for each server. Persistent in-process Cache is when you back up your cache outside of process memory.
Right-click on the Start button and click on Task Manager. 2. On the Task Manager screen, click on the Performance tab > click on CPU in the left pane. In the right-pane, you will see L1, L2 and L3 Cache sizes listed under “Virtualization” section.
1. use _cache. ToArray() or _cache. ToList() instead of _cache then you can start use LINQ.
Memory caching (often simply referred to as caching) is a technique in which computer applications temporarily store data in a computer's main memory (i.e., random access memory, or RAM) to enable fast retrievals of that data. The RAM that is used for the temporary storage is known as the cache.
Here is a better way to enumerate and get the result:
public virtual List<T> GetCache<T>()
{
List<T> list = new List<T>();
IDictionaryEnumerator cacheEnumerator = (IDictionaryEnumerator)((IEnumerable)Cache).GetEnumerator();
while (cacheEnumerator.MoveNext())
list.Add((T) cacheEnumerator.Value);
return list;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With