Search code examples
javaehcacheehcache-3

In EhCache3 should I have a single CacheManager for all caches or one manager per cache


I am using Ehcache 3

I have one cache for storing one type of object, and another cache for a different type. These are in separate classes and each have their own cache manager.

But Im now wondering if I have misunderstood the examples and it would make more sense to have one CacheManager managing both different caches, or are you only meant to use the same CacheManager to manage multiple caches of the same type.

Because the examples like to chain together the code it is very unclear from the documentation what the correct approach is.


Solution

  • One CacheManager. All caches in it.

    Which example are you talking about?

    A cache manager without any cache:

    CacheManager cacheManager = CacheManagerBuilder.newCacheManagerBuilder() 
        .build(true);