ehcache / ehcache3

Ehcache 3.x line
http://www.ehcache.org
Apache License 2.0
2k stars 578 forks source link

getOccupiedByteSize() is not working when Heap entries is mentioned in ResourcePoolsBuilder #3207

Closed DanaWhite30 closed 8 months ago

DanaWhite30 commented 8 months ago

Using ehcache 3.10

StatisticsService statisticsService = new DefaultStatisticsService();

CacheManager cacheManager = CacheManagerBuilder.newCacheManagerBuilder()
                .using(statisticsService)
                .build(true);

CacheConfiguration config = CacheConfigurationBuilder.newCacheConfigurationBuilder(String.class, String.class,
        ResourcePoolsBuilder.newResourcePoolsBuilder().heap(10)).build();  // heap 10 entries
Cache<String, String> cache = cacheManager.createCache("preConfigured",config);
cache.put("key1", "value1");
cache.put("key2", "value2");
cache.put("key3", "value3");

long currentMemory = statisticsService.getCacheStatistics("preConfigured").getTierStatistics().get("OnHeap").getOccupiedByteSize();
System.out.println(currentMemory);  // -1 is printed

when ResourcePoolsBuilder is changed to use memory size it works fine.

chrisdennis commented 8 months ago

Heap tiers that are entry sized do not track their byte sizes by design since the sizing operations that would be needed carry significant overhead.

DanaWhite30 commented 8 months ago

Is there any other way to calculate the heap size of the cache object ?