I have a pretty standard persistence layer setup in my Spring driven application using Hibernate (4.2.15.Final) with EhCache (2.6.9) as 2nd level cache.
Everything works as expected. However, putting entries into the 2nd level cache sometimes takes ages.
I've configured caching of my domain model classes in an explicit ehcache.xml
file (I didn't configure a default cache):
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd"
name="hibernate"
updateCheck="false"
monitoring="autodetect"
dynamicConfig="false"
maxBytesLocalHeap="300M"
maxBytesLocalDisk="500M">
<cache
name="org.mycorp.model.MyEntity"
eternal="true"
overflowToDisk="false"
diskPersistent="false"
maxBytesLocalHeap="5M" />
...
</ehcache>
I get the following INFO message logged at startup of the persistence context:
DefaultSizeOfEngine | using Agent sizeof engine
and the following WARNING during execution
ObjectGraphWalker | The configured limit of 1,000 object references was reached while attempting to calculate the size of the object graph. Severe performance degradation could occur if the sizing operation continues. [...]
AFAIK the ObjectGraphWalker
has to size the entities that are put into the cache, because I configured the single cache regions with maxBytesLocalHeap
.
My domain model is quite complex and I know that I can limit the walking of the graph with @IgnoreSizeOf
annotations, but I'm uncertain how to tackle the problem:
- Do I have to ignore one side of a bidirectional association to avoid cycles?
- Do I have to explicitly ignore transient members of my domain model classes?
- In general, is it wise to go with
maxBytesLocalHeap
when using EhCache together with Hibernate or should I settle formaxEntriesLocalHeap
, because Hibernate is keeping a separate cache region for each entity anyway?
[UPDATE]: I discovered, that transient members will not be cached by Hibernate (see Hibernate: Is it possible to save a transient field in second level cache?), so they should not be regarded by ehcache anyway. Correct?