I use org.ehcache, and ran into a problem that I can’t find out how much ehcache ate memory to display in the console, I will be grateful for the help. I use spring 4.1.6, org.ehcache 3.0.3
1 answer
I am not familiar with api , but having rummaged in the source code, I found the following. If cache is on-heap , then you can reach the occupied size as follows:
Ehcache has a private field:
private final Store<K, V> store; the OnHeapStore class that implements the Store interface contains a field
private volatile Backend<K, V> map; But the Backend interface has several interesting methods:
/** * Returns the computed size in bytes, if configured to do so * * @return the computed size in bytes */ long byteSize(); /** * Returns the natural size, that is byte sized if configured, count size otherwise. * * @return the natural size */ long naturalSize(); I dare to assume that these are the methods you need.
- not that ((this is some sort of pool size, and when I add a cache, the result does not change. And by this method, getSize of all the cache is beautiful (1000, 50, 100, 2000), and considering how much data I have there like small results - Elizar
- ok, updated the answer - Artem Konovalov
- Thanks, I looked at your option, and without a clue how to get to these fields (and there are many packet classes. - Elizar
- @Elizar reflection - Artem Konovalov
|