Terracotta 10.15 | Ehcache API Developer Guide | Configuration Derivation | Core Configuration Changes
 
Core Configuration Changes
The configuration builder returned by the derive method provides direct methods for modifying core configuration concepts:
Setting a custom class loader:
Configuration withClassLoader = configuration.derive()
.withClassLoader(classLoader)
.build();
Adding a cache:
Configuration withCache = configuration.derive()
.withCache("cache", CacheConfigurationBuilder.newCacheConfigurationBuilder(
Long.class, String.class, ResourcePoolsBuilder.heap(10)))
.build();
<ehcache>
</ehcache>
-->
<ehcache>
<cache alias="cache">
<key-type>Long.class</key-type>
<value-type>Object.class</value-type>
<heap>10</heap>
</cache>
</ehcache>
Removing a cache:
Configuration withoutCache = configuration.derive()
.withoutCache("cache")
.build();
<ehcache>
<cache alias="cache">
<key-type>Long.class</key-type>
<value-type>Object.class</value-type>
<heap>10</heap>
</cache>
</ehcache>
-->
<ehcache>
</ehcache>
Updating a cache configuration uses a UnaryOperator that is run against a cache configuration builder seeded by the existing cache configuration.
Updating a cache, by adding a resource:
Configuration withOffHeap = configuration.derive()
.updateCache("cache", cache -> cache.updateResourcePools(
resources -> ResourcePoolsBuilder.newResourcePoolsBuilder(resources)
.offheap(100, MemoryUnit.MB)
.build()))
.build();
<ehcache>
<cache alias="cache">
<key-type>Long.class</key-type>
<value-type>Object.class</value-type>
<heap>10</heap>
</cache>
</ehcache>
-->
<ehcache>
<cache alias="cache">
<key-type>Long.class</key-type>
<value-type>Object.class</value-type>
<resources>
<heap>10</heap>
<offheap unit="MB">100</offheap>
</resources>
</cache>
</ehcache>