I am running a large VM in production and would like to understand more about my cache size at runtime. My caches are all based upon ehache
What is the best way to s
In EhCache 3 (at least in the 3.5 version that I uses) you can access cache size via the cache statistics.
First, you need to register the statistic service on your cache manager :
StatisticsService statisticsService = new DefaultStatisticsService();
CacheManager cacheManager = CacheManagerBuilder.newCacheManagerBuilder()
.using(statisticsService)
.build();
cacheManager.init();
Then, you can retrieve the statistics on your cache and it contains size by tiers (in EhCache 3 you have three different tiers : heap, disk and offheap)
CacheStatistics ehCacheStat = statisticsService.getCacheStatistics("myCache");
ehCacheStat.getTierStatistics().get("OnHeap").getMappings();//nb element in heap tier
ehCacheStat.getTierStatistics().get("OnHeap").getOccupiedByteSize()//size of the tier