Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I determine programmatically if ehcache is running?

Tags:

ehcache

I have a large java application that is configured to use JPA and Hibernate. It is also supposedly configured to use ehcaching for both entity and query caching. However, I have sql logging turned on and no entities are being cached. All of the entity queries are happening on every request.

How can I determine at runtime if it is even running ehcache and whether it thinks an entity should be cacheable?

I didn't write this app so I'm stuck a bit here.

It uses declarations for the caching on the classes.

It is correctly using all the other declarations for Hibernate to perform the read/write operations.

like image 692
Andrew Avatar asked Jan 08 '11 22:01

Andrew


People also ask

How do I know if Ehcache is working in spring boot?

We can use Maven to start this app by running mvn spring-boot:run. Then open up a browser and access the REST service on port 8080. The log message in the square method of NumberService isn't being invoked. This shows us that the cached value is being used.

How do I know how much my Ehcache is worth?

ehcache. hibernate under Mbeans tab. Click on the CacheRegionStats Clicking on it will open bring up the screen on the right. Double click on top section and it brings up the tabular navigation as shown below.

What is difference between Ehcache and Redis cache?

You can think Redis as a shared data structure, while Ehcache is a memory block storing serialized data objects. This is the main difference. Redis as a shared data structure means you can put some predefined data structure (such as String, List, Set etc) in one language and retrieve it in another language.


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());
        }
}
like image 128
mglauche Avatar answered Oct 25 '22 14:10

mglauche


The short answer - a debugger.

Put a breakpoint where you load an entity and follow it down the stack. See if it ever even attempts to get the object from EHCache. Also, check to see if it tries to put it in the cache after it fetches it from the DB.

like image 21
rfeak Avatar answered Oct 25 '22 14:10

rfeak