Wednesday, 27 June 2012

Choosing Hibernate Cache Provider

Choosing a cache provider
 
For now, Hibernate forces you to choose a single cache provider for the whole application. Providers for the following products are built into Hibernate:
 
EHCache is intended for a simple process scope cache in a single JVM. It can cache in memory or on disk, and it supports the optional Hibernate query result cache.
OpenSymphony OSCache is a library that supports caching to memory and disk in a single JVM, with a rich set of expiration policies and query cache support.
SwarmCache is a cluster cache based on JGroups. It uses clustered invalidation but doesn’t support the Hibernate query cache.
JBossCache is a fully transactional replicated clustered cache also based on the JGroups multicast library. The Hibernate query cache is supported, assuming that clocks are synchronized in the cluster. It’s easy to write an adaptor for other products by implementing net.sf.hibernate.cache.CacheProvider.
 
Not every cache provider is compatible with every concurrency strategy. The
compatibility matrix in table will help you choose an appropriate combination.
 
Cache concurrency strategy support
 
Cache Provider read-only
 
Non strict read-write read-write transactional
 
EHCache X X X  
OSCache X X X  
SwarmCache X X    
JBossCache X     X