0

I am in interested to know if the Hibernate Second-Level caching can be shared between two different Hibernate session running on two different JVM.

I am using Hibernate 3.1 with Ehcache to provide second-level caching, and in the Ehcache.xml config file we can specify where we like to create the cache on the disk

    <ehcache>
        <diskStore path="C:\Learn\db"/>
</ehcache>

So If I now open two different Hibernate session, in different JVMs where both pointing to the same , will that allow me to share the second-level cache between two JVM.

If this is the case. so if one of the Hibernate session update its cache (session level cache), will the subsequently update the second-level cache and hence the second session running on different JVM when access that cache will get the updated data.

many thanks.

Adnan Mian
  • 415
  • 1
  • 5
  • 17

2 Answers2

1

Yes you can, I don't know about ehcache but infinispan allows you to do this (assuming you are sharing a database)

https://docs.jboss.org/author/display/ISPN/Using+Infinispan+as+JPA-Hibernate+Second+Level+Cache+Provider

DaveB
  • 2,953
  • 7
  • 38
  • 60
1

You can use any of the ehcache replication/clustering mechanisms with your Hibernate second level caches. See either:

Now, depending on the which replication/clustering solution you go for, all caching strategies might not be recommended, but at least it wouldn't require a full XA environment.

Alex Snaps
  • 1,230
  • 10
  • 10