Terracotta Ehcache 10.7 | Ehcache API Developer Guide | Creating and Configuring a CacheManager Using Java | Creating a Cache Manager with Clustering Support
 
Creating a Cache Manager with Clustering Support
To enable clustering with Terracotta, firstly you will have to start the Terracotta server configured with clustered storage. In addition, for creating the cache manager with clustering support, you will need to provide the clustering service configuration:

CacheManagerBuilder<PersistentCacheManager>
clusteredCacheManagerBuilder =
CacheManagerBuilder.newCacheManagerBuilder() // <1>
.with(ClusteringServiceConfigurationBuilder.cluster(URI.create(
"terracotta://localhost:9410/my-application")) // <2>
.autoCreate()); // <3>
PersistentCacheManager cacheManager =
clusteredCacheManagerBuilder.build(true); // <4>

cacheManager.close(); // <5>
<1>
Returns the org.ehcache.config.builders.CacheManagerBuilder instance;
<2>
Use the ClusteringServiceConfigurationBuilder's static method cluster(URI) for connecting the cache manager to the clustering storage at the URI specified that returns the clustering service configuration builder instance. The sample URI provided in the example points to the clustered storage with clustered storage identifier my-application on the Terracotta server (assuming the server is running on localhost and port 9410); the query-param auto-create creates the clustered storage in the server if it doesn't already exist.
<3>
Returns a fully initialized cache manager that can be used to create clustered caches.
<4>
Close the cache manager.