
javadoc.com.google.common.cache.CacheStats.html Maven / Gradle / Ivy
The newest version!
CacheStats (Guava: Google Core Libraries for Java 11.0.1 API)
Overview
Package
Class
Use
Tree
Deprecated
Index
Help
PREV CLASS
NEXT CLASS
FRAMES
NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD
DETAIL: FIELD | CONSTR | METHOD
com.google.common.cache
Class CacheStats
java.lang.Object
com.google.common.cache.CacheStats
@Beta
@GwtCompatible
public final class CacheStats
- extends Object
Statistics about the performance of a Cache
. Instances of this class are immutable.
Cache statistics are incremented according to the following rules:
- When a cache lookup encounters an existing cache entry
hitCount
is incremented. - When a cache lookup first encounters a missing cache entry, a new entry is loaded.
- After successfully loading an entry
missCount
andloadSuccessCount
are incremented, and the total loading time, in nanoseconds, is added tototalLoadTime
. - When an exception is thrown while loading an entry,
missCount
andloadExceptionCount
are incremented, and the total loading time, in nanoseconds, is added tototalLoadTime
. - Cache lookups that encounter a missing cache entry that is still loading will wait
for loading to complete (whether successful or not) and then increment
missCount
.
- After successfully loading an entry
- When an entry is evicted from the cache,
evictionCount
is incremented. - No stats are modified when a cache entry is invalidated or manually removed.
- No stats are modified by operations invoked on the asMap view of the cache.
- Since:
- 10.0
- Author:
- Charles Fry
Constructor Summary | |
---|---|
CacheStats(long hitCount,
long missCount,
long loadSuccessCount,
long loadExceptionCount,
long totalLoadTime,
long evictionCount)
Constructs a new CacheStats instance. |
Method Summary | |
---|---|
double |
averageLoadPenalty()
Returns the average time spent loading new values. |
boolean |
equals(Object object)
|
long |
evictionCount()
Returns the number of times an entry has been evicted. |
int |
hashCode()
|
long |
hitCount()
Returns the number of times Cache lookup methods have returned a cached value. |
double |
hitRate()
Returns the ratio of cache requests which were hits. |
long |
loadCount()
Returns the total number of times that Cache lookup methods attempted to load new
values. |
long |
loadExceptionCount()
Returns the number of times Cache lookup methods threw an exception while loading a
new value. |
double |
loadExceptionRate()
Returns the ratio of cache loading attempts which threw exceptions. |
long |
loadSuccessCount()
Returns the number of times Cache lookup methods have successfully loaded a new value. |
CacheStats |
minus(CacheStats other)
Returns a new CacheStats representing the difference between this CacheStats
and other . |
long |
missCount()
Returns the number of times Cache lookup methods have returned an uncached (newly
loaded) value, or null. |
double |
missRate()
Returns the ratio of cache requests which were misses. |
CacheStats |
plus(CacheStats other)
Returns a new CacheStats representing the sum of this CacheStats
and other . |
long |
requestCount()
Returns the number of times Cache lookup methods have returned either a cached or
uncached value. |
String |
toString()
|
long |
totalLoadTime()
Returns the total number of nanoseconds the cache has spent loading new values. |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
CacheStats
public CacheStats(long hitCount, long missCount, long loadSuccessCount, long loadExceptionCount, long totalLoadTime, long evictionCount)
- Constructs a new
CacheStats
instance.Five parameters of the same type in a row is a bad thing, but this class is not constructed by end users and is too fine-grained for a builder.
Method Detail |
---|
requestCount
public long requestCount()
- Returns the number of times
Cache
lookup methods have returned either a cached or uncached value. This is defined ashitCount + missCount
.
hitCount
public long hitCount()
- Returns the number of times
Cache
lookup methods have returned a cached value.
hitRate
public double hitRate()
- Returns the ratio of cache requests which were hits. This is defined as
hitCount / requestCount
, or1.0
whenrequestCount == 0
. Note thathitRate + missRate =~ 1.0
.
missCount
public long missCount()
- Returns the number of times
Cache
lookup methods have returned an uncached (newly loaded) value, or null. Multiple concurrent calls toCache
lookup methods on an absent value can result in multiple misses, all returning the results of a single cache load operation.
missRate
public double missRate()
- Returns the ratio of cache requests which were misses. This is defined as
missCount / requestCount
, or0.0
whenrequestCount == 0
. Note thathitRate + missRate =~ 1.0
. Cache misses include all requests which weren't cache hits, including requests which resulted in either successful or failed loading attempts, and requests which waited for other threads to finish loading. It is thus the case thatmissCount >= loadSuccessCount + loadExceptionCount
. Multiple concurrent misses for the same key will result in a single load operation.
loadCount
public long loadCount()
- Returns the total number of times that
Cache
lookup methods attempted to load new values. This includes both successful load operations, as well as those that threw exceptions. This is defined asloadSuccessCount + loadExceptionCount
.
loadSuccessCount
public long loadSuccessCount()
- Returns the number of times
Cache
lookup methods have successfully loaded a new value. This is always incremented in conjunction withmissCount
, thoughmissCount
is also incremented when an exception is encountered during cache loading (seeloadExceptionCount
). Multiple concurrent misses for the same key will result in a single load operation.
loadExceptionCount
public long loadExceptionCount()
- Returns the number of times
Cache
lookup methods threw an exception while loading a new value. This is always incremented in conjunction withmissCount
, thoughmissCount
is also incremented when cache loading completes successfully (seeloadSuccessCount
). Multiple concurrent misses for the same key will result in a single load operation.
loadExceptionRate
public double loadExceptionRate()
- Returns the ratio of cache loading attempts which threw exceptions. This is defined as
loadExceptionCount / (loadSuccessCount + loadExceptionCount)
, or0.0
whenloadSuccessCount + loadExceptionCount == 0
.
totalLoadTime
public long totalLoadTime()
- Returns the total number of nanoseconds the cache has spent loading new values. This can be
used to calculate the miss penalty. This value is increased every time
loadSuccessCount
orloadExceptionCount
is incremented.
averageLoadPenalty
public double averageLoadPenalty()
- Returns the average time spent loading new values. This is defined as
totalLoadTime / (loadSuccessCount + loadExceptionCount)
.
evictionCount
public long evictionCount()
- Returns the number of times an entry has been evicted. This count does not include manual
invalidations.
minus
public CacheStats minus(CacheStats other)
- Returns a new
CacheStats
representing the difference between thisCacheStats
andother
. Negative values, which aren't supported byCacheStats
will be rounded up to zero.
plus
public CacheStats plus(CacheStats other)
- Returns a new
CacheStats
representing the sum of thisCacheStats
andother
.- Since:
- 11.0
hashCode
public int hashCode()
equals
public boolean equals(@Nullable Object object)
toString
public String toString()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Copyright © 2010-2012. All Rights Reserved.
© 2015 - 2025 Weber Informatics LLC | Privacy Policy