views:

245

answers:

1

Hello all!

I am interested in getting statistics on the Ehcache I have running.

I would like to see the number of hits/misses for a given key over a period of time. Perhaps in the form of a map. For example.

For the passed hour (or however long it has been running)

Key A had 30 hits and 2 misses
Key B had 400 hits and 100 misses
Key C had 2 hits and 1 misses
Key D had 150 hits and 10 misses

I have looked through the documentation (SampledCacheStatistics, SampledCacheStatisticsImpl, SampledCacheStatisticsWrapper, etc) and I am having a terrible time figuring this out.

Has anyone else had experience implementing this?

Any help or ideas on this would be MUCH appreciated!

+1  A: 

The EhCache Monitor gives you that type of information... http://ehcache.org/documentation/monitor.html

Programmatic access is available as follows:

    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());
    }
Jan