Caching strategies
One of the most important features of a relational database is support for concurrency and how multiple users can read from and write to the database. This is known as isolation level. The same concept is applicable in ORM cache.
Hibernate has built-in support for various concurrency strategies and isolation levels for a second-level cache. In this section, we will discuss various strategies and when you should use one over the other.
You should keep in mind that Hibernate defines its own isolation level, but a cache provider may offer other levels. When you choose a provider, you should consult the documentation to find out what isolation levels are supported. For example, Ehcache only supports READ-COMMITTED. However, Ehcache can in fact participate in JTA transaction (global transaction) and, therefore, supports two-phase commit.
Hibernate provides an interface to access strategy for different types, such as EntityRegionAccessStrategy
, which specifies the contract to access...