Here is what the Ehcache Official Documentation says about calibrating cached records:
Calibrate Cached Records
Items cached with a limited amount of memory will have their measured memory sizes. The entire Element instance added to the cache is measured, including the key and value, as well as the amount of memory to add this instance for internal data structures. Key and value measurement as graphic objects - each link is executed, and the link object is also measured. This happens recursively.
Shared links will be measured by each class that references it. This will lead to overstatement. Shared links should therefore be ignored.
Configuration to limit the schedule of the moved object
Calibrating caches involves moving graphs of objects, a process that may be limited to annotations. This process can also be controlled both at the CacheManager level and on the cache.
Control how much the size of the engine can move when configuring heap elements by adding the next element at the CacheManager level.
<sizeOfPolicy maxDepth="100" maxDepthExceededBehavior="abort" />
This item has the following attributes:
maxDepth , which controls how many related objects can be visited before the size of the engine takes any action. This attribute is required .
maxDepthExceededBehavior , which indicates what happens when the maximum depth is exceeded when determining the size of the object. Possible values for this application:
continue , which forces the size of the engine to register a warning and continue the calibration operation. If this attribute is not specified, continue is the behavior used.
abort , which causes the size of the engine to cancel calibration, logging warnings, and flagging the cache as improperly tracking memory usage This setting returns Ehcache.hasAbortedSizeOf() true
The SizeOf policy can be configured at the cache manager level (directly under <ehcache> ) and at the cache level (under <cache> or <defaultCache> ). A cache policy always overrides cache manager one, if both are installed. This element does not affect distributed caches.
source share