I am using Ehcache 3.10. I am using persistent cache, configured as follows:
PersistentCacheManager persistentCacheManager = CacheManagerBuilder.newCacheManagerBuilder()
.with(CacheManagerBuilder.persistence("\ + File.separator + "squaredValue"))
.withCache("persistent-cache",
CacheConfigurationBuilder.newCacheConfigurationBuilder(Integer.class, Integer.class,
ResourcePoolsBuilder.newResourcePoolsBuilder()
.heap(10, EntryUnit.ENTRIES)
.disk(10, MemoryUnit.MB, true)))
.build(true);
Cache<Integer, Integer> squareNumberCache = persistentCacheManager.createCache(
"squaredNumber",
CacheConfigurationBuilder.newCacheConfigurationBuilder(Integer.class,
Integer.class,
ResourcePoolsBuilder.heap(10)));
Based on file size, it seems the cache is getting persisted to disk. I have a few questions:
- I am assuming the config is setting up a two tier cache - Heap and Disk. Is my understanding correct?
- When does data from the Heap get persisted to the disk? Or is that always happening?
- Is there a way I can control when data gets persisted to disk? (As a way to improve performance by lowering the write to disk.)
- When the app restarts, the cache does not seem to be hydrated from the disk. Can someone please share sample config / startup code to load the data in disk to cache.
Thank you in advance, Ahmed.