Summary
EhCache is often used as Hibernate's second-level cache, but many other caching options are also available for Hibernate applications. What distributed second-level cache do you prefer to use with Hibernate?
Advertisement
As Matt Raible notes in his latest blog post, as of Hibernate 3.2, EhCache is no longer Hibernate's default second-level cache, due to some incompatibilities between the most recent, distributed version of EhCache and its older siblings.
In his blog post, Raible lists a few other caching options available to Hibernate applications, such as OSCache, noting that:
I've used OSCache in the past. It worked well, but it was kind of annoying that I had to patch Hibernate to make it work. The Hibernate folks say it's OSCache's fault, the OSCache guys say it's Hibernate's fault—so this issue will likely never get resolved...
That leaves JBoss TreeCache, EhCache and OSCache as choices for a clusterable 2nd-level cache. OSCache is an invalidating cache, which definitely works—but might not work as you expect it to. JBoss Cache only seems to allow a replicated cache which also works. EhCache seems to support both. I don't know if invalidating or replicating is better, but I imagine replicating can get quite chatty if you're dealing with large amounts of data.
But wait—is there another open source option? According to Terracotta's CTO, Terracotta is much faster than JBoss Cache. However, if you read about it ... you'll see that JBoss Cache has no "official" benchmarks.
Raible only lists open-source cache solutions, noting that possibly the best solution may be Tangosol's Coherence, which is proprietary.
What is your experience with the various distributed second-level caches for Hibernate? What distributed cache do you prefer?
> Raible only lists open-source cache solutions, noting > that possibly the best solution may be Tangosol's > Coherence, which is proprietary.
Coherence, as it is today, works with Hibernate out-of-the-box, but it is not always the best solution, because Hibernate doesn't always take full advantage of the capabilities that Coherence offers.
On the other hand, we are working on changing that, including adding some cache strategies to Hibernate, and then Coherence will almost always be the best solution for clustered caching with Hibernate :-)