Is there a way to look through the cache for all objects in the cache? I'm dynamically creating objects and I need to periodically go through the list to purge out objects I'm no longer using.
var keysToClear = (from System.Collections.DictionaryEntry dict in HttpContext.Cache
let key = dict.Key.ToString()
where key.StartsWith("Something_")
select key).ToList();
foreach (var key in keysToClear)
{
HttpContext.Cache.Remove(key);
}
You can enumerate through the objects:
System.Web.HttpContext.Current.Cache.GetEnumerator()
Yes, you can either index based on the cache key, or you you can iterate over the contents:
For Each c In Cache
' Do something with c
Next
' Pardon my VB syntax if it's wrong
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