Iterate through a CacheManager?

Topics: Caching Application Block
Dec 26, 2006 at 11:19 PM
Hi folks,

how could one iterate through all the results in a cache manager? I noticed that it is not IEnumerable. The reason being was that i was trying to make a data grid visual representation of some CacheManager chached results and therefore using GeDate is irrelivent because we do not know they keys to retrieve.

I'm guessing this is not possible due to performance issues, hence the functionality not added?
Dec 27, 2006 at 9:31 PM
It is definitely not possible in Enterprise Library 1.0 and 2.0, and I just checked for version 3.0, and it is still not possible to iterate through the collection of cached items in the cachemanager.

Although I don't know for sure, I believe your instincts are correct. Enumerating the items in a cachemanager could lead to some concurrency issues regarding enumerating a collection that could change as well as perhaps some performance issues depending on the collection you are enumerating, which could be a database or unknown custom caching provider with unknown performance implications.

Although this isn't a solution per se, the Ent Lib 2.0 documentation recommends creating a cache manager per object type. Thus, you would have separate cache managers for Products, Orders, Categories, etc.

By doing this, it makes it easier to flush objects of a particular type, which is often what you might want to do when iterating a collection. Well, maybe not, but it is food for thought :)

Again, the above is really not a solution, but may provide some ideas to help with the fact that you cannot iterate a collection as of this moment. Maybe they may add it during the CTP cycle of Enterprise Library 3.0, but it may not be practial given that we are talking about persistent caching and it has performance implications.


Microsoft MVP C#