ehcache

net.sf.ehcache.jcache
Class JCacheStatistics

java.lang.Object
  extended by net.sf.ehcache.jcache.JCacheStatistics
All Implemented Interfaces:
java.io.Serializable, net.sf.jsr107cache.CacheStatistics

public class JCacheStatistics
extends java.lang.Object
implements net.sf.jsr107cache.CacheStatistics, java.io.Serializable

A jsr107 CacheStatistics decorator for an ehcache Statistics class. An immutable Cache statistics implementation}

This is like a value object, with the added ability to clear cache statistics on the cache. That ability does not survive any Serialization of this class. On deserialization the cache can be considered disconnected.

The accuracy of these statistics are determined by the value of {#getStatisticsAccuracy()} at the time the statistic was computed. This can be changed by setting Cache.setStatisticsAccuracy(int).

Because this class maintains a reference to an Ehcache, any references held to this class will precent the Ehcache from getting garbage collected.

Version:
$Id: JCacheStatistics.java 519 2007-07-27 07:11:45Z gregluck $
Author:
Greg Luck
See Also:
Serialized Form

Field Summary
 
Fields inherited from interface net.sf.jsr107cache.CacheStatistics
STATISTICS_ACCURACY_BEST_EFFORT, STATISTICS_ACCURACY_GUARANTEED, STATISTICS_ACCURACY_NONE
 
Constructor Summary
JCacheStatistics(Statistics statistics)
          Constructs an object from an ehcache statistics object
 
Method Summary
 void clearStatistics()
          Clears the statistic counters to 0 for the associated Cache.
 float getAverageGetTime()
          The average time for cache gets since either the cache was created or statistics were cleared
 int getCacheHits()
          The number of times a requested item was found in the cache.
 int getCacheMisses()
          Warning.
 long getEvictionCount()
          Gets the number of cache evictions, since the cache was created, or statistics were cleared.
 int getObjectCount()
          Gets the number of elements stored in the cache.
 int getStatisticsAccuracy()
          Accurately measuring statistics can be expensive.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JCacheStatistics

public JCacheStatistics(Statistics statistics)
Constructs an object from an ehcache statistics object

Parameters:
statistics - the Statistics object this object decorates.
Method Detail

getStatisticsAccuracy

public int getStatisticsAccuracy()
Accurately measuring statistics can be expensive. Returns the current accuracy setting used in the creation of these statistics.

Specified by:
getStatisticsAccuracy in interface net.sf.jsr107cache.CacheStatistics
Returns:
one of CacheStatistics.STATISTICS_ACCURACY_BEST_EFFORT, CacheStatistics.STATISTICS_ACCURACY_GUARANTEED, CacheStatistics.STATISTICS_ACCURACY_NONE

clearStatistics

public void clearStatistics()
Clears the statistic counters to 0 for the associated Cache.

Specified by:
clearStatistics in interface net.sf.jsr107cache.CacheStatistics

getCacheHits

public int getCacheHits()
The number of times a requested item was found in the cache.

Warning. This statistic is recorded as a long. If the statistic is large than Integer#MAX_VALUE precision will be lost.

Specified by:
getCacheHits in interface net.sf.jsr107cache.CacheStatistics
Returns:
the number of times a requested item was found in the cache

getCacheMisses

public int getCacheMisses()
Warning. This statistic is recorded as a long. If the statistic is large than Integer#MAX_VALUE precision will be lost.

Specified by:
getCacheMisses in interface net.sf.jsr107cache.CacheStatistics
Returns:
the number of times a requested element was not found in the cache

getObjectCount

public int getObjectCount()
Gets the number of elements stored in the cache. Caclulating this can be expensive. Accordingly, this method will return three different values, depending on the statistics accuracy setting.

Best Effort Size

This result is returned when the statistics accuracy setting is Statistics.STATISTICS_ACCURACY_BEST_EFFORT.

The size is the number of Elements in the MemoryStore plus the number of Elements in the DiskStore.

This number is the actual number of elements, including expired elements that have not been removed. Any duplicates between stores are accounted for.

Expired elements are removed from the the memory store when getting an expired element, or when attempting to spool an expired element to disk.

Expired elements are removed from the disk store when getting an expired element, or when the expiry thread runs, which is once every five minutes.

Guaranteed Accuracy Size

This result is returned when the statistics accuracy setting is Statistics.STATISTICS_ACCURACY_GUARANTEED.

This method accounts for elements which might be expired or duplicated between stores. It take approximately 200ms per 1000 elements to execute.

Fast but non-accurate Size

This result is returned when the statistics accuracy setting is CacheStatistics.STATISTICS_ACCURACY_NONE.

The number given may contain expired elements. In addition if the DiskStore is used it may contain some double counting of elements. It takes 6ms for 1000 elements to execute. Time to execute is O(log n). 50,000 elements take 36ms.

Specified by:
getObjectCount in interface net.sf.jsr107cache.CacheStatistics
Returns:
the number of elements in the ehcache, with a varying degree of accuracy, depending on accuracy setting.

getAverageGetTime

public float getAverageGetTime()
The average time for cache gets since either the cache was created or statistics were cleared


getEvictionCount

public long getEvictionCount()
Gets the number of cache evictions, since the cache was created, or statistics were cleared.


ehcache