0

What I think about Replicating the second level cache of hibernate ::

Suppose we hit one URL to find an Employee Object and it came into the SessionFactory of say node1 (one node of cluster). [SQL Query will be fired to fetch the Employee Object by Hibernate]

If I again hit the URL to find the Employee Object and this time call goes to node2 (another node of Cluster), The SQL Query will not be fired this time. And data will be fetched from the Second Level cache replicated from node1 to node2.

Kindly validate my understanding. I am trying to create a small project to understand this.

Sunny Gupta
  • 6,929
  • 15
  • 52
  • 80

2 Answers2

1

Without replication, the data in node1's cache will be different than the data in node2's cache.

Ehcache does have built-in facilities for replicating across nodes. This article will give you more information about the RMI-based implementation.

You might also find distributed caches like memcached worth looking into. This page describes the benefits it provides over a replicated cache (tl;dr: bigger cache size). Here is a library providing memcached support for hibernate.

Floegipoky
  • 3,087
  • 1
  • 31
  • 47
1

You can achieve this with Infinispan, out of the box, and using a more efficient replication method than RMI... I have some standalone examples that match precisely this use case, i.e. https://github.com/galderz/secondlc/blob/master/src/test/java/secondlc/Cluster2lcTest.java

Galder ZamarreƱo
  • 5,027
  • 2
  • 26
  • 34