Terracotta 10.3 | Ehcache API Developer Guide | Hybrid Caching | Example of a Hybrid Scenario
 
Example of a Hybrid Scenario

EnterpriseServerSideConfigurationBuilder serverSideConfigBuilder =
EnterpriseClusteringServiceConfigurationBuilder
.enterpriseCluster(connectionURI.resolve("/cacheManager"))
.autoCreate()
.defaultServerResource("primary-server-resource")
.restartable("data-directory-name")
.withRestartableOffHeapMode(RestartableOffHeapMode.PARTIAL); // 1

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

ClusteredResourcePool pool1 = ClusteredRestartableResourcePoolBuilder
.clusteredRestartableDedicated(
"primary-server-resource", 4, MemoryUnit.MB, 25); // 2

ClusteredResourcePool pool2 = ClusteredRestartableResourcePoolBuilder
.clusteredRestartableDedicated(
"primary-server-resource", 12, MemoryUnit.MB, 50); // 3

Cache<Long, String> restartableDedicatedPoolCache = cacheManager
.createCache("restartableDedicatedPoolCache", CacheConfigurationBuilder
.newCacheConfigurationBuilder(Long.class, String.class,
ResourcePoolsBuilder.newResourcePoolsBuilder().with(pool1))); // 4

Cache<Long, String> restartableSharedPoolCache = cacheManager
.createCache("restartableSharedPoolCache", CacheConfigurationBuilder
.newCacheConfigurationBuilder(Long.class, String.class,
ResourcePoolsBuilder.newResourcePoolsBuilder().with(pool2))); // 5

cacheManager.close();
cacheManager.destroy();
1
Creates a hybrid CacheManager.
2
Creates a pool of size 4 MB from primary-server-resource, with a dataPercent value of 25.
3
Creates a pool of size 12 MB from primary-server-resource, with a dataPercent value of 50.
4
Creates a Cache using pool1 created from Step 2 above.
5
Creates a Cache using pool2 created from Step 3 above.

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.