Is there any tool available for viewing cached data in HttpRunTime cache..?
We have an Asp.Net application which is caching data into HttpRuntime Cache. Default value given was 60 seconds, but later changed to 5 minutes. But feels that the cached data is refreshing before 5 minutes. Don't know what is happening underneath.
Is there any tool available or how we can see the data cached in HttpRunTime Cache.... with expiration time...?
Following code is using for add items to cache.
public static void Add(string pName, object pValue)
{
int cacheExpiry= int.TryParse(System.Configuration.ConfigurationManager.AppSettings["CacheExpirationInSec"], out cacheExpiry)?cacheExpiry:60;
System.Web.HttpRuntime.Cache.Add(pName, pValue, null, DateTime.Now.AddSeconds(cacheExpiry), TimeSpan.Zero, System.Web.Caching.CacheItemPriority.High, null);
}
Thanks.
The Cache class supports an IDictionaryEnumerator to enumerate over all keys and values in the cache.
IDictionaryEnumerator enumerator = System.Web.HttpRuntime.Cache.GetEnumerator();
while (enumerator.MoveNext())
{
string key = (string)enumerator.Key;
object value = enumerator.Value;
...
}
But I don't believe there is any official way to access metadata such as expiration time.
Cache class supports an IDictionaryEnumerator to enumerate over all keys and values in the cache. The below code is an example for how to delete every key from cache:
List<string> keys = new List<string>();
// retrieve application Cache enumerator
IDictionaryEnumerator enumerator = System.Web.HttpRuntime.Cache.GetEnumerator();
// copy all keys that currently exist in Cache
while (enumerator.MoveNext())
{
keys.Add(enumerator.Key.ToString());
}
// delete every key from cache
for (int i = 0; i < keys.Count; i++)
{
HttpRuntime.Cache.Remove(keys[i]);
}
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