[Logo] Terracotta Discussion Forums (LEGACY READ-ONLY ARCHIVE)
  [Search] Search   [Recent Topics] Recent Topics   [Members]  Member Listing   [Groups] Back to home page 
[Register] Register / 
[Login] Login 
[Expert]
Not getting ehCache statistics  XML
Forum Index -> Ehcache
Author Message
sphinx

journeyman

Joined: 10/01/2010 12:45:29
Messages: 26
Offline

I am using ehCache 2.0 with Hibernate 3.5

Caching seems to be enabled. We can see cache .data files created in store directory. I see ehCache debug messages:

DEBUG [net.sf.ehcache.hibernate.AbstractEhcacheRegionFactory] - <Creating EhCacheRegionFactory from a specified resource: HibernateCache.xml.
DEBUG [net.sf.ehcache.config.ConfigurationFactory] - <Configuring ehcache from URL:...
DEBUG [net.sf.ehcache.config.ConfigurationFactory] - <Configuring ehcache from InputStream>
DEBUG [net.sf.ehcache.config.DiskStoreConfiguration] - <Disk Store Path: ...
 



However, I cannot get ehCache statistics:
http://ehcache.org/apidocs/index.html?net/sf/ehcache/Statistics.html

I am trying to get Statistics object using following code:

Code:
CacheManager cacheManager = CacheManager.getInstance();
 String[] cacheNames = cacheManager.getCacheNames();
 for (int i = 0; i < cacheNames.length; i++) {
     String cacheName = cacheNames[i];
     System.out.println(cacheName+" - "+  cacheManager.getCache(cacheName).getStatistics().toString());
 }
 


But getCacheNames() returns an empty array.
Is there any other way to access ehCache statistics in JUnit tests?
alexsnaps

consul

Joined: 06/19/2009 09:06:00
Messages: 484
Offline

Couple of questions, do you enable statistics in your ehcache config file?
Also, it seems you do configure it using HibernateCache.xml, but later in your code you don't specify a config file, and call for the default CacheManager.getInstance(). You do create two different CacheManager instances if I am not mistaken...

Alex Snaps (Terracotta engineer)
sphinx

journeyman

Joined: 10/01/2010 12:45:29
Messages: 26
Offline

Thank you for quick reply!

I have statistics enabled in ehCache config:
<defaultCache .... statistics=true /> 


In hibernate.xml I have:
<property name="hibernate.cache.use_second_level_cache" value="true" />
<property name="hibernate.cache.region.factory_class" value="net.sf.ehcache.hibernate.EhCacheRegionFactory" />
<property name="net.sf.ehcache.configurationResourceName" value="HibernateCache.xml" />
<property name="hibernate.cache.use_query_cache" value="true" />
<property name="hibernate.cache.use_structured_entries" value="true" />
<property name="hibernate.generate_statistics" value="true" />
 


I thought that when I define configurationResourceName in hibernate.xml file it becomes the default ehCache configuration file.

I changed my code and it worked. I am getting all may cache stats.

Code:
CacheManager manager = new CacheManager("src/config/HibernateCache.xml");
 
 
Forum Index -> Ehcache
Go to:   
Powered by JForum 2.1.7 © JForum Team