Hibernate: query cache has never been used

While doing some performance tuning in my application, I noticed that the sleep cache is never used.

I am sure I configured it correctly:

  • hibernate.cache.provider_class = org.hibernate.cache.EhCacheProvider
  • hibernate.cache.use_query_cache = true
  • I use setCacheable(true)for queries that I want to cache

I set up a simple stress test when I perform the same set of operations over and over in multiple threads. When I check the hibernation statistics, it turns out that the hitCount request cache is zero!

What am I missing?

EDIT:
If you all ask: I installedhibernate.generate_statistics = true

+3
source share
3 answers

I set up a simple stress test when I perform the same set of operations over and over in multiple threads. When I check the hibernation statistics, it turns out that the hitCount request cache is zero!

Well, although you can get statistics about cache hits from statistics ( if you enable statistics by setting the property hibernate.generate_statistics=truein your configuration), this IMO is not the best way to diagnose caching of "problems".

My suggestion was to enable logging of 1. DML statements executed and 2. cache activity. Relevant logging categories:

  • org.hibernate.SQL Record all SQL DML statements at run time.
  • org.hibernate.cache Register all second level cache activity.

, , .

+2

, hibernate.cache.use_second_level_cache=true|false?

+1

Hibernate does not collect statistics by default. Have you included statistics?

  • hibernate.generate_statistics = true
0
source

Source: https://habr.com/ru/post/1761332/


All Articles