public class CacheStatistics extends java.lang.Object implements CacheStatisticsMBean, java.io.Serializable
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.Modifier and Type | Field and Description |
---|---|
private Ehcache |
ehcache |
private long |
lastUpdated |
private javax.management.ObjectName |
objectName |
private static long |
serialVersionUID |
private Statistics |
statistics |
private long |
ttlInMillis |
Constructor and Description |
---|
CacheStatistics(Ehcache ehcache)
Constructs an object from an ehcache statistics object using the default statistics ttl.
|
CacheStatistics(Ehcache ehcache,
long ttl,
java.util.concurrent.TimeUnit unit)
Constructs an object from an ehcache statistics object
|
Modifier and Type | Method and Description |
---|---|
void |
clearStatistics()
Clears the statistic counters to 0 for the associated Cache.
|
(package private) static javax.management.ObjectName |
createObjectName(java.lang.String cacheManagerName,
java.lang.String cacheName)
Creates an object name using the scheme "net.sf.ehcache:type=CacheStatistics,CacheManager=
|
java.lang.String |
getAssociatedCacheName() |
double |
getCacheHitPercentage()
Returns the percentage of cache accesses that found a requested item in the cache.
|
long |
getCacheHits()
The number of times a requested item was found in the cache.
|
long |
getCacheMisses()
Warning.
|
double |
getCacheMissPercentage()
Returns the percentage of cache accesses that did not find a requested element in the cache.
|
long |
getDiskStoreObjectCount()
Gets the number of objects in the DiskStore
|
Ehcache |
getEhcache()
Return the backing cache.
|
double |
getInMemoryHitPercentage()
Returns the percentage of cache accesses that found a requested item cached in-memory.
|
long |
getInMemoryHits()
Number of times a requested item was found in the Memory Store.
|
long |
getInMemoryMisses() |
long |
getMemoryStoreObjectCount()
Gets the number of objects in the MemoryStore
|
long |
getObjectCount()
Gets the number of elements stored in the cache.
|
(package private) javax.management.ObjectName |
getObjectName() |
double |
getOffHeapHitPercentage()
Returns the percentage of cache accesses that found a requested item cached off-heap.
|
long |
getOffHeapHits()
Number of times a requested item was found in the off-heap store.
|
long |
getOffHeapMisses() |
long |
getOffHeapStoreObjectCount()
Gets the number of objects in the OffHeapStore
|
double |
getOnDiskHitPercentage()
Returns the percentage of cache accesses that found a requested item cached on disk.
|
long |
getOnDiskHits()
Number of times a requested item was found in the Disk Store.
|
long |
getOnDiskMisses() |
private static double |
getPercentage(long number,
long total) |
int |
getStatisticsAccuracy()
Accurately measuring statistics can be expensive.
|
java.lang.String |
getStatisticsAccuracyDescription()
Accurately measuring statistics can be expensive.
|
int |
getWriterMaxQueueSize()
Gets the maximum size of the write-behind queue, if any.
|
long |
getWriterQueueLength()
Gets the size of the write-behind queue, if any.
|
private void |
updateIfNeeded() |
private static final long serialVersionUID
private final transient Ehcache ehcache
private final javax.management.ObjectName objectName
private final long ttlInMillis
private Statistics statistics
private long lastUpdated
public CacheStatistics(Ehcache ehcache, long ttl, java.util.concurrent.TimeUnit unit)
ehcache
- the backing ehcachettl
- statistics ttl valueunit
- statistics ttl unitpublic CacheStatistics(Ehcache ehcache)
ehcache
- the backing ehcachestatic javax.management.ObjectName createObjectName(java.lang.String cacheManagerName, java.lang.String cacheName)
public int getStatisticsAccuracy()
getStatisticsAccuracy
in interface CacheStatisticsMBean
Statistics.STATISTICS_ACCURACY_BEST_EFFORT
, Statistics.STATISTICS_ACCURACY_GUARANTEED
, Statistics.STATISTICS_ACCURACY_NONE
private void updateIfNeeded()
public java.lang.String getStatisticsAccuracyDescription()
getStatisticsAccuracyDescription
in interface CacheStatisticsMBean
public java.lang.String getAssociatedCacheName()
getAssociatedCacheName
in interface CacheStatisticsMBean
public void clearStatistics()
clearStatistics
in interface CacheStatisticsMBean
public long getCacheHits()
getCacheHits
in interface CacheStatisticsMBean
public long getInMemoryHits()
getInMemoryHits
in interface CacheStatisticsMBean
public long getOffHeapHits()
getOffHeapHits
in interface CacheStatisticsMBean
public long getOnDiskHits()
getOnDiskHits
in interface CacheStatisticsMBean
public long getCacheMisses()
getCacheMisses
in interface CacheStatisticsMBean
public long getInMemoryMisses()
getInMemoryMisses
in interface CacheStatisticsMBean
public long getOffHeapMisses()
getOffHeapMisses
in interface CacheStatisticsMBean
public long getOnDiskMisses()
getOnDiskMisses
in interface CacheStatisticsMBean
public long getObjectCount()
Statistics.STATISTICS_ACCURACY_BEST_EFFORT
.
The size is the number of Element
s in the MemoryStore
plus
the number of Element
s 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.
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.
Statistics.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.getObjectCount
in interface CacheStatisticsMBean
public long getWriterQueueLength()
getWriterQueueLength
in interface CacheStatisticsMBean
public int getWriterMaxQueueSize()
getWriterMaxQueueSize
in interface CacheStatisticsMBean
public long getMemoryStoreObjectCount()
getMemoryStoreObjectCount
in interface CacheStatisticsMBean
public long getOffHeapStoreObjectCount()
getOffHeapStoreObjectCount
in interface CacheStatisticsMBean
public long getDiskStoreObjectCount()
getDiskStoreObjectCount
in interface CacheStatisticsMBean
javax.management.ObjectName getObjectName()
public Ehcache getEhcache()
private static double getPercentage(long number, long total)
public double getCacheHitPercentage()
getCacheHitPercentage
in interface CacheStatisticsMBean
public double getCacheMissPercentage()
getCacheMissPercentage
in interface CacheStatisticsMBean
public double getInMemoryHitPercentage()
getInMemoryHitPercentage
in interface CacheStatisticsMBean
public double getOffHeapHitPercentage()
getOffHeapHitPercentage
in interface CacheStatisticsMBean
public double getOnDiskHitPercentage()
getOnDiskHitPercentage
in interface CacheStatisticsMBean