Get all Cached Objects which are cached using MemoryCache class c#
This is what i found (it may help some one)
foreach (var item in MemoryCache.Default)
{
//add the item.keys to list
}
return list;
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;
}
This should also work: MemoryCache.Default.ToList();