Search code examples
javahibernatejpahazelcastsecond-level-cache

HazelCast distributed second level cache and update invalidation


I am using hibernate 5 and hazelcast 3.5.4. For second level cache I use HazelcastCacheRegionFactory which happens to be the distributed implementation.

HazelcastLocalCacheRegionFactory documentation states clearly that in case of an update/delete invalidation messages are send.

I did a test in a local network with a two node clustered second level cache. Once an entity is read from a node the other node does not access the database, instead it fetches the entity from hazelcast. However once a node updates an entity the other node in order to fetch the entity does a query.

So my question is if HazelcastCacheRegionFactory sends invalidation messages too on update/delete instead of propagating the changes.

Thank you.


Solution

  • So my question is if HazelcastCacheRegionFactory sends invalidation messages too on update/delete instead of propagating the changes.

    No, it doesn't, changes are propagated, as described in the documentation:

    HazelcastCacheRegionFactory uses standard Hazelcast Distributed Maps. All operations like get, put, and remove will be performed using the Distributed Map logic. The only downside of using HazelcastCacheRegionFactory may be the lower performance compared to HazelcastLocalCacheRegionFactory since operations are handled as distributed calls.

    I think that the negative performance impact of a distributed Hibernate L2 cache is not emphasized enough in the above docs, as in practice it can be so large that it is faster to read data from the db directly, as I explained here.