Hibernate has two caches, a session cache and a second level cache. The session cache is used for one session only and doesn't cache objects between sessions. I'm not talking about this cache, I'm talking about the secend level cache which is by default ehcache.
Using the
nonestrict-read-write strategie, my research shows that the cache works as long as you do read only access, e.g.:
Session-1 load( X ) -> select X .... (DB access)
Session-2 load( X ) -> ehcache hit (no DB access)
Session-3 load( X ) -> ehcache hit (no DB access)
If your business logic requires modifications to the object it is thrown out of the cache, e.g.:
Session-1 load( X ) -> select X .... (DB access)
Session-1 save( X ) -> update X .... (DB access and removal from cache)
Session-2 load( X ) -> select X .... (DB access)
Session-2 save( X ) -> update X .... (DB access and removal from cache)
Session-3 load( X ) -> select X .... (DB access)
Session-3 save( X ) -> update X .... (DB access and removal from cache)
I wonder why this is done since it wasts a lot of resources. If I update the object I have the current state of the object, why should I throw it out of the cache?
Using the
read-write strategie the cache works as expected:
Session-1 load( X ) -> select X .... (DB access)
Session-1 save( X ) -> update X .... (DB access)
Session-2 load( X ) -> ehcache hit (no DB access)
Session-2 save( X ) -> update X .... (DB access)
Session-3 load( X ) -> ehcache hit (no DB access)
Session-3 save( X ) -> update X .... (DB access)
The documentation leaves it open what the different cache strategies do or not. Why should I chose nonestrict-read-write, where is the advantage over read-write? How do they compare to the JDBC transaction isolation levels? The transactional strategie "provides support for fully transactional cache providers" and what does that mean? Do the other cache strategies violate the ACID rule? Do certain strategies lock resources? What happens in case of a deadlock?
Can sombody shed some light on it? Post his experience with the different strategies?