|
First-Level and Second-Level CachesHibernate implements a simple session-level cache, useful on a per-transaction basis. This cache is primarily used to optimize the SQL generated by Hibernate. It is sometimes referred to as a first-level Hibernate cache.
The following figure shows Hibernate operating with a single JVM cache used to minimize traffic between Hibernate and the database. This will increase the performance of the application and minimize the load on the database, but at the cost of a bit more configuration complexity (described later in this section) and memory usage. If you are interested in sharing object data across threads, simply use a cache, as shown in the following figure.
The following figure illustrates a problem that may arise when you use a cache. If your application does not have exclusive access to the database (a common situation in an enterprise environment), your cache can easily become out of sync with the database. If a legacy application updates a record stored in the cache, by default there is no notification to the cache that the data is stale, and therefore the data in the cache will be incorrect.
Multiple SessionFactory ObjectsA JVM cache, as described here, is actually a SessionFactory-level cache. There is normally no reason not to share a SessionFactory instance throughout your JVM instance; but if for some reason your application uses more than one SessionFactory, you're effectively building a multiple JVM system, and therefore you will need to use a distributed/clustered cache.
If you are able to control all the access to a particular database instance, you may be able to use the GigaSpaces distributed cache to ensure that the data traffic is properly synchronized. An example of this is shown in the following figure. Since the overhead accessing GigaSpaces cache is minimal, there would not be any performance impact when adding the cache layer.
|
Wiki Content Tree
Your Feedback Needed!
We need your help to improve this wiki site. If you have any suggestions or corrections, write to us at techw@gigaspaces.com. Please provide a link to the wiki page you are referring to.




Add Comment