Although this question concerns EhCache primarily, it really applies to caching frameworks (and plain old caching) in general.
EhCache allows you to create a singleton CacheManager for managing all of the Caches in your application, or it allows you to create “instance” CacheManager, which means exactly what it sounds like: multiple managers in use throughout your application.
What are the pros/cons of each? At first glimpse it seems like it would be cleaner to just have a singleton manager.
The only conceivable reason I can think of for why one would want multiple instance managers is the fact that all caches living inside a CacheManager must share the same configurations: same size, usage strategies, capacities, etc. So if you wanted multiple caches, each configured differently, the singleton CacheManager would not be able to provided the different cache configurations to each cache.
Is this the only criteria for determining singleton vs instance managers? If not, what are some other considerations? Is there a noticeable performance cost associated with either? Thanks in advance!
What about automated testing? Maybe it can be useful for unit testing if you can enable/disable/configure caching on a smaller level? Just a thought.