Terracotta 10.7 | Ehcache API Developer Guide | Creating and Configuring a CacheManager Using Java | Configuring Storage Tiers using Java
 
Configuring Storage Tiers using Java
Ehcache offers a tiering model that allows storing increased amounts of less frequently used data on slower tiers (which are generally more abundant).
More frequently used data (the "hottest data") would preferably be stored on faster (commonly less abundant) storage, whereas less frequently used data (less "hot" data) can be moved to slower (commonly more abundant) storage tiers.
Three Tiers
A classical example would be using 3 tiers with a persistent disk storage.

PersistentCacheManager persistentCacheManager =
CacheManagerBuilder.newCacheManagerBuilder()
.with(CacheManagerBuilder.persistence(
new File(getStoragePath(), "myData"))) // <1>
.withCache("threeTieredCache",
CacheConfigurationBuilder.newCacheConfigurationBuilder(
Long.class, String.class,
ResourcePoolsBuilder.newResourcePoolsBuilder()
.heap(10, EntryUnit.ENTRIES) // <2>
.offheap(1, MemoryUnit.MB) // <3>
.disk(20, MemoryUnit.MB, true) // <4>
)
).build(true);

Cache<Long, String> threeTieredCache =
persistentCacheManager.getCache("threeTieredCache",
Long.class, String.class);
threeTieredCache.put(1L, "stillAvailableAfterRestart"); // <5>

persistentCacheManager.close();
1. If you wish to use disk storage (in the same way as for persistent Cache instances), you have to provide a location where data should be stored on disk to the CacheManagerBuilder.persistence() static method.
2. Define a resource pool for the heap. This will be your faster but smaller pool.
3. Define a resource pool for the off-heap. This is still quite fast and a bit bigger.
4. Define a persistent resource pool for the disk. It is persistent because the last parameter is true.
5. All values stored in the cache will be available after a JVM restart (assuming the CacheManager has been closed cleanly by calling close()).