One or many cache managers?

Topics: Caching Application Block
Jun 9, 2009 at 3:50 PM


I'm starting to use the Caching Application Blocks, and was wondering what are the tradeoffs between having a single big cache manager or many smaller ones.

In my scenario, its an ASP.NET app. The main use will be caching DataTables based on a parent id for different types of information, like products, clients, places, codes, etc. But the pattern is always "int key -> DataTable data".

I'm willing to store about 1000 DataTables for each group, and the expiration policy for them is the same (15 - 30 minutes). This data changes once a day actually, but we may refresh it manually if needed.

My questions are:

- Would it be better to create a single Cache Manager with a capacity of 5000 items and use key patterns like "Product_123", "Client_546", or 5 CacheManagers with capacity of 1000 for each one?

- Are there any problems in having like 20-30 cache managers in a single app? Would I have 30 background processes doing the expiration/scavenging?

- And what if I'm working with small sets of data, say, 20 groups/10 to 30 objects per group, would it be better to have a single cache manager for them or still split?


Jun 10, 2009 at 11:49 AM


One thing I can think about having multiple cache manager is it will require you to write more code since you will be resolving and manipulating each cache, which means it would require you more effort. Compared to when you are using a single cache manager and that manager is set as default cache manager you can resolve it without specifying the name. For the performance, I tried to create a simple app which uses caching. I have 2 cache manager, one with 100000 objects and the other 50000. I used tracing to find out if there would be performance difference when you try to retrieve item from the cache with more object versus the cache with lesser object. And the result, there is not much big difference. Maybe you could try this one also.

Valiant Dudan
Global Technology and Solutions
Avanade, Inc.

Jun 10, 2009 at 3:22 PM

Thank you.

As for the coding effort, there wouldn't be any difference, as compared to the application code, one line or two for that is nothing. =)

I thought people already had done some benchmarking on that.

But if looking up in 50000 items is quick enough, I think I can centralize all lookup information in a single cache manager with about 10000 items. we have plenty of memory, since this data is static for all users, using up to 1 gb of space won't hurt.

I think my main worry was if the background scheduler would lock the list when scavenging or expiring items, but it seems it locks only the item, not the entire list.

I'll do some tests and see what I can get.