Terracotta Ehcache 10.1 | Ehcache API Developer Guide | Clustered Caches | Creating a Cache Manager with Clustering Capabilities
 
Creating a Cache Manager with Clustering Capabilities
After starting the Terracotta Server, as described in the previous section, you can now proceed to create the cache manager. For creating the cache manager with clustering support you will need to provide the clustering service configuration. Here is a code sample that shows how to configure a cache manager with clustering service.

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 clustered storage at the URI specified that returns the clustering service configuration builder instance. Sample URI provided in the example is pointing to the clustered storage instance named "my-application" on the Terracotta Server (assuming the server is running on localhost and port 9410.
3
Auto-create the clustered storage if it doesn't already exist.
4
Returns a fully initialized cache manager that can be used to create clustered caches.
5
Close the cache manager.

Copyright © 2010-2019 | Software AG, Darmstadt, Germany and/or Software AG USA, Inc., Reston, VA, USA, and/or its subsidiaries and/or its affiliates and/or their licensors.
Innovation Release