Hello
I am new the working with hibernate second level cache and query cache.
In my current work, I am working with a legacy application. There is lot of code that does following
- Execute a complex query (legacy have to look in few tables to make sure it does not exist)
- if no results returned then insert
We were thinking of using query cache to cache these expensive queries. However from what I have read is that once a query is executed its result will be cached.
Therefore in above scenario - if we re-execute same query we will always get a empty result.
What will be the proper way to do this?
a. Do not search - insert and catch ConstraintViolationException to determine entity exist?
b. Put these query in a region and purge that region on insert
c. Change CacheMode to refresh after insert and run the query for new entity to be cached
d. Do not cache these queries
Thank You for the help