Possible bug: Setting isolation level disables query cache #2887
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
We discovered an issue, that the query cache does not work, when isolation level is set.
use case
We show a counter in the UI how many unread messages a user has. It is important, that this method is fast and does not block so we set READ_UNCOMMITED. We also want to use the query-cache in this case.
As we only want to show an indicator of unread messages, it is not important to get the exact correct number. (it is better to get a possible wrong number than blocking the UI request when some tables are locked)
What happens
TransactionFactory.setIsolationLevel calls connection and JdbcTransaction.connection sets
queryOnly = false
: https:/ebean-orm/ebean/blob/master/ebean-core/src/main/java/io/ebeaninternal/server/transaction/JdbcTransaction.java#L768Question
Is this really a bug or intended, that the query cache will be disabled when isolation level is changed?
I know, that the result of READ_UNCOMMITTED may differ from the cache. But it seems it does not matter to which value you set the isolation level.