How to determine programmatically if ehcache is running?

I have a large Java application that is configured to use JPA and Hibernate. It is also assumed that it uses ehcaching to cache objects and queries. However, I have sql accounting enabled, and no objects are cached. All entity queries occur for each query.

How can I determine at runtime if it even starts ehcache and does it consider the object to be cacheable?

I did not write this application, so it got a little stuck here.

It uses declarations for caching in classes.

Correctly use all the other ads for Hibernate to perform read / write operations.

+4
source share
2 answers

Try something like this:

List<CacheManager> tempManagers = CacheManager.ALL_CACHE_MANAGERS; System.out.println("# of CMs : " + tempManagers.size()); for (CacheManager tempCM : tempManagers) { System.out.println("Got: " + tempCM.getName()); String[] cacheNames = tempCM.getCacheNames(); for (int i = 0; i < cacheNames.length; i++) { String cacheName = cacheNames[i]; System.out.println(cacheName+" - "+ tempCM.getEhcache(cacheName).getStatistics().toString()); } } 
+2
source

The short answer is a debugger.

Place a breakpoint where you load the object and follow it along the stack. See if he is even trying to get an object from EHCache. Also, check to see if he is trying to cache it after he retrieves it from the database.

+1
source

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


All Articles