Monitoring Enterprise Library caching

2019-06-12 08:58发布

问题:

I want to monitor the key names and values that are being stored by my application in the Enterprise Library caching mechanism.

We're using the in memory settings. Basically, I just need to figure out how to dump the keys that are currently stored.

I see that the ICacheManager returns an object that has a counter, but there doesn't appear to be a way to access the cached items unless you already know the key.

Ideas?

回答1:

You are correct - Enterprise Lib does not expose the in memory Cache of the CashManager. But... there is always a work around. You can reference the downloaded sourced as a project modify the original CacheManager to expose the instance of cache which has a property called CurrentCacheState and is a mere hashtable. Then you would do the usual foreach:

    foreach(DictionaryEntry d in myExposedCacheManager.RealCache.CurrentCacheState) 
    {

         Console.WriteLine(d.Key.ToString(), d.Value.ToString();
    }