Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hibernate Query cache invalidation

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

like image 921
Nihal Narayanan Avatar asked Sep 11 '25 20:09

Nihal Narayanan


1 Answers

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 off using a native query instead and take advantage of database indexing and proper buffer pool tuning.

like image 198
Vlad Mihalcea Avatar answered Sep 13 '25 10:09

Vlad Mihalcea