1 Static method org.ehcache.config.builders.CacheManagerBuilder.newCacheManagerBuilder that returns a new org.ehcache.config.builders.CacheManagerBuilder instance;

2 Use the builder to register a pre-configured Cache to be created when we .build() the actual CacheManager . The first String argument is the alias used to interact with the Cache through the CacheManager ; the second argument is org.ehcache.config.CacheConfiguration to configure the Cache . We use the static .newCacheConfigurationBuilder() method on org.ehcache.config.builders.CacheConfigurationBuilder to create a default config;

3 Finally, invoking .build() returns a fully instantiated, but uninitialized, CacheManager we can use;

4 Before you start to use the CacheManager it needs to be init() , which can be done for you by the builder by passing true to build(boolean) ;

5 We can retrieve the preConfigured aliased Cache we declared in step 2. For type-safety, we ask for both key and value types to be passed in. If these differ from the ones we expect, the CacheManager throws a ClassCastException early in the application’s lifecycle. It also guards the Cache from being polluted by random types.

6 The CacheManager can also be used to create new Cache as needed. Just as in step 2, it requires passing in an alias as well as a CacheConfiguration . The instantiated and fully initialized Cache added will be returned and/or accessed through the CacheManager.getCache API.

7 We can now use the newly added Cache to store and …​

8 …​ retrieve data.

9 We can also CacheManager.removeCache(String) a given Cache . The CacheManager will not only remove it’s reference to the Cache , but will also close it. The Cache releases all locally held transient resources (such as memory). References to this Cache become unusable.