Hi Gunnar,
also with read/write your are able to keep the cache in sync with the database.
In our company we use now EHCache with read/write since more than a year,
and we never experienced stale data in 2L-Cache.
Quote:
when do I really need transactional?
The unique difference I saw between using transactional Infinispan and read/write EHCache is following:
Transactional:
Once a entity object was cached, it never was reread from database again,
also when performing updates on that object, followed either by commits or rollbacks:
the 2Lcache always had the correct (up-todate) object cached.
Non Transactional (read/write):
In this configuration in contrast to Transactional the 2L-cache is usually not able to maintain multiple versions (=states) of the same entity object, thus when you modify an object and flush, the regarding object (update to the new values) in 2L-Cache get locked until your transaction ends. While this Lock this entity in 2L-Cache is not accessible to other concurrent transactions (otherwise it would violate isolation levels), so on demand they will re-read that object from database again.
Similiar thing happens when you finally rollback your transaction instead to commit it:
The 2L-cache don't has a copy of your entity object in original state, so it is not able to turn back to it's original state: the entry gets discarded.
So on next demand, that entity object must be read again from database, (after this, it will be reput into 2LCache again).
Conclusion:
Transactional 2L-cache is better for
high-concurrency access,
that means when concurrent threads are very often
accessing and updating the same entity objects.
If indeed updates are not so often and if it not represents a problem to you,
that sometimes an object is even reread from database again,
then also non Transactional 2L-cache should work well to you.