I am using Hibernate(with JPA) in an application that has a high write-read ratio. For caching I have enabled query-cache and hibernate second level cache(ehcache). The problem I am facing is due to automatic query cache invalidation when an update is done. Is there any way to configure query cache to update its values instead of invalidating them? Also, since I am using queries to fetch entities, avoiding query-cache is also not an option
Best How To :
The query cache is not useful for write-mostly applications, as you probably figured out yourself. There is no write-through query caching option, so you need to question why you are using this feature in the first place.
The entity caching is useful when you plan on changing those entities you’re querying. If you only need projections/views for rendering a table or something similar, then you are better of using a native query instead and take advantage of database indexing.
There are other data access alternatives, like Speedment ORM, which can speed up data retrieval considerably (but not JPA compliant).