Cache capacity limitation

Topics: Building and extending application blocks, Caching Application Block
Mar 8, 2007 at 9:33 AM
I plan to use the Caching block in our new project. I am quite happy with the features and flexibility it provides. However, I have two questions here and hope someone can give me some advices.

Currently, we use the maximumElementsInCacheBeforeScavenging to limit the maximum amount of items that can be stored in a cache. Does anyone has the experience of change this to limit the amount of memory usage instead?

I also consider specified a very large number for maximumElementsInCacheBeforeScavenging so it can use as much memory as avaialbe in the cache server. What happened when the memory is not big enough to hold all the items in the cache but the number of items still less than the maximumElementsInCacheBeforeScavenging setting so the scavenging task is not kick in yet? Will the application that using the caching block crash? or just slow down?

Thank you
Mar 13, 2007 at 2:23 PM
I recommend seriously considering leveraging the Caching done in System.Web before using the block. It sounds like you really want Memory Caching and want a mechanism that scavenges based on memory, which is what the ASP.NET Caching Does. I also don't see a lot of features being added to the Caching Application Block in the future.

If you still prefer the Caching Block...

The In-Memory Cache is just a Hashtable so I don't know how easily / accurate it is to determine the amount of memory it consumes and scavenge from it based on a maximum memory threshold. I recommend making sure you can do this before tackling the new scavenging policy.

It also doesn't look to me based on the code that the EntLib Team had any plan for other scavenging policies because they didn't offer any extensibility or extension points around the scavenging policy. I have never tried creating a scavenging policy associated with memory but it may be a bit of work because you don't have an Interface or other level of abstraction to work with. You may want to add the extensibility point using the current scavenging policy before making the new scavenging policy.

Again, I would check the System.Web Caching first, but good luck.




David Hayden
Microsoft MVP C#
Mar 16, 2007 at 10:23 AM
Thank you for your reply.

I did check the ASP.NET cache first, though we only need in-memory cache currently, there are some features in enterprise cache are quite attracting. For example, we can change the code little bit to support generic(use generic dictionary instead of hashtable), set up different cache managers which store different types of objects in the same cache server.

So we will use the enterprise caching block unless we found some problems with it that conflict with our requirements.