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. Caches must be configured as restartable in a restartable CacheManager. A non-restartable CacheManager can not 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:9510/my-application")) // 1
.autoCreate()
.defaultServerResource("primary-server-resource")
.restartable("data-root-identifier"); // 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 9510).
2
restartable(String) accepts a logical data root identifier 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 the CacheManager 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.
Copyright © 2010-2017 Software AG, Darmstadt, Germany. (Innovation Release)

Product LogoContact Support   |   Community   |   Feedback