Terracotta Ehcache 10.7 | Ehcache API Developer Guide | Fast Restartability | Creating a Restartable Cache Manager
 
Creating a Restartable Cache Manager
Configuring a restartable server lays the foundation for application data to be restartable.
Refer to the topic Server Persistence in the section Configuring the Terracotta Server for information on configuring a restartable server.
Caches must be configured as restartable in a restartable CacheManager. A non-restartable CacheManager cannot contain restartable Caches. However, a restartable CacheManager can contain restartable as well as non-restartable Caches. In the latter case, only the Cache configuration is restored upon a server restart, and not the Cache data.
The following example illustrates a restartable CacheManager creation. Only the parts which are different in a restartable CacheManager are explained.

EnterpriseServerSideConfigurationBuilder serverSideConfigBuilder =
EnterpriseClusteringServiceConfigurationBuilder
.enterpriseCluster(URI.create(
"terracotta://localhost:9410/my-application")) // 1
.autoCreate()
.defaultServerResource("primary-server-resource")
.restartable("data-directory-name") // 2

PersistentCacheManager cacheManager = CacheManagerBuilder
.newCacheManagerBuilder()
.with(serverSideConfigBuilder) // 3
.build(true);

cacheManager.close();
cacheManager.destroy(); // 4
1
EnterpriseClusteringServiceConfigurationBuilder's static method enterpriseCluster(URI) connects the cache manager to the clustered storage at the URI specified. The sample URI provided in the example points to the clustered storage instance named 'my-application' on the Terracotta Server (assuming the server is running on localhost and port 9410).
2
The restartable(String) method accepts a logical data directory name to specify where the fast restart logs should be stored.
The string specified here is a logical name, which should be present in the Terracotta Server configuration. The server configuration has a mapping of this logical name to a directory path. Using this API is an absolute MUST to create a restartable CacheManager, in the absence of which theCacheManager will be created as a non-restartable CacheManager.
3
CacheManagerBuilder uses serverSideConfigBuilder created in Step 1 above.
4
Calling destroy() on the CacheManager will destroy all caches contained inside the CacheManager, all associated metadata and the CacheManager itself. This can be done to free up resources and to ensure that cache contents don't re-appear on a server restart.