Top Description Fields Constructors Methods
com.google.common.cache

public final Class CacheStats

extends Object
Class Inheritance
Annotations
@GwtCompatible
@ElementTypesAreNonnullByDefault
Static Imports
com.google.common.base.Preconditions.checkArgument, com.google.common.math.LongMath.saturatedAdd, .LongMath.saturatedSubtract

Statistics about the performance of a Cache. Instances of this class are immutable.

Cache statistics are incremented according to the following rules:

A lookup is specifically defined as an invocation of one of the methods LoadingCache#get(Object), LoadingCache#getUnchecked(Object), Cache#get(Object, Callable), or LoadingCache#getAll(Iterable).

Author
Charles Fry
Since
10.0

Field Summary

Modifier and TypeField and Description
private final long
private final long
private final long
private final long
private final long
private final long

Constructor Summary

AccessConstructor and Description
public
CacheStats(long hitCount, long missCount, long loadSuccessCount, long loadExceptionCount, long totalLoadTime, long evictionCount)

Constructs a new CacheStats instance.

Method Summary

Modifier and TypeMethod and Description
public double
averageLoadPenalty()

Returns the average time spent loading new values.

public boolean
equals(Object
the reference object with which to compare.
object
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.
public long
evictionCount()

Returns the number of times an entry has been evicted.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for the object.
public long
hitCount()

Returns the number of times Cache lookup methods have returned a cached value.

public double
hitRate()

Returns the ratio of cache requests which were hits.

public long
loadCount()

Returns the total number of times that Cache lookup methods attempted to load new values.

public long
loadExceptionCount()

Returns the number of times Cache lookup methods threw an exception while loading a new value.

public double
loadExceptionRate()

Returns the ratio of cache loading attempts which threw exceptions.

public long
loadSuccessCount()

Returns the number of times Cache lookup methods have successfully loaded a new value.

public CacheStats
minus(CacheStats other)

Returns a new CacheStats representing the difference between this CacheStats and other.

public long
missCount()

Returns the number of times Cache lookup methods have returned an uncached (newly loaded) value, or null.

public double
missRate()

Returns the ratio of cache requests which were misses.

public CacheStats
plus(CacheStats other)

Returns a new CacheStats representing the sum of this CacheStats and other.

public long
requestCount()

Returns the number of times Cache lookup methods have returned either a cached or uncached value.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
public long
totalLoadTime()

Returns the total number of nanoseconds the cache has spent loading new values.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

evictionCountback to summary
private final long evictionCount
hitCountback to summary
private final long hitCount
loadExceptionCountback to summary
private final long loadExceptionCount
loadSuccessCountback to summary
private final long loadSuccessCount
missCountback to summary
private final long missCount
totalLoadTimeback to summary
private final long totalLoadTime
Annotations
@SuppressWarnings:GoodTime

Constructor Detail

CacheStatsback to summary
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.

Annotations
@SuppressWarnings:GoodTime

Method Detail

averageLoadPenaltyback to summary
public double averageLoadPenalty()

Returns the average time spent loading new values. This is defined as totalLoadTime / (loadSuccessCount + loadExceptionCount).

Note

the values of the metrics are undefined in case of overflow (though it is guaranteed not to throw an exception). If you require specific handling, we recommend implementing your own stats collector.

equalsback to summary
public boolean equals(Object object)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
object:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
evictionCountback to summary
public long evictionCount()

Returns the number of times an entry has been evicted. This count does not include manual invalidations.

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for the object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object.

Annotations
@Override
hitCountback to summary
public long hitCount()

Returns the number of times Cache lookup methods have returned a cached value.

hitRateback to summary
public double hitRate()

Returns the ratio of cache requests which were hits. This is defined as hitCount / requestCount, or 1.0 when requestCount == 0. Note that hitRate + missRate =~ 1.0.

loadCountback to summary
public long loadCount()

Returns the total number of times that Cache lookup methods attempted to load new values. This includes both successful load operations and those that threw exceptions. This is defined as loadSuccessCount + loadExceptionCount.

Note

the values of the metrics are undefined in case of overflow (though it is guaranteed not to throw an exception). If you require specific handling, we recommend implementing your own stats collector.

loadExceptionCountback to summary
public long loadExceptionCount()

Returns the number of times Cache lookup methods threw an exception while loading a new value. This is usually incremented in conjunction with missCount, though missCount is also incremented when cache loading completes successfully (see loadSuccessCount). Multiple concurrent misses for the same key will result in a single load operation. This may be incremented not in conjunction with missCount if the load occurs as a result of a refresh or if the cache loader returned more items than was requested. missCount may also be incremented not in conjunction with this (nor loadSuccessCount) on calls to getIfPresent.

loadExceptionRateback to summary
public double loadExceptionRate()

Returns the ratio of cache loading attempts which threw exceptions. This is defined as loadExceptionCount / (loadSuccessCount + loadExceptionCount), or 0.0 when loadSuccessCount + loadExceptionCount == 0.

Note

the values of the metrics are undefined in case of overflow (though it is guaranteed not to throw an exception). If you require specific handling, we recommend implementing your own stats collector.

loadSuccessCountback to summary
public long loadSuccessCount()

Returns the number of times Cache lookup methods have successfully loaded a new value. This is usually incremented in conjunction with missCount, though missCount is also incremented when an exception is encountered during cache loading (see loadExceptionCount). Multiple concurrent misses for the same key will result in a single load operation. This may be incremented not in conjunction with missCount if the load occurs as a result of a refresh or if the cache loader returned more items than was requested. missCount may also be incremented not in conjunction with this (nor loadExceptionCount) on calls to getIfPresent.

minusback to summary
public CacheStats minus(CacheStats other)

Returns a new CacheStats representing the difference between this CacheStats and other. Negative values, which aren't supported by CacheStats will be rounded up to zero.

missCountback to summary
public long missCount()

Returns the number of times Cache lookup methods have returned an uncached (newly loaded) value, or null. Multiple concurrent calls to Cache lookup methods on an absent value can result in multiple misses, all returning the results of a single cache load operation.

missRateback to summary
public double missRate()

Returns the ratio of cache requests which were misses. This is defined as missCount / requestCount, or 0.0 when requestCount == 0. Note that hitRate + 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 that missCount >= loadSuccessCount + loadExceptionCount. Multiple concurrent misses for the same key will result in a single load operation.

plusback to summary
public CacheStats plus(CacheStats other)

Returns a new CacheStats representing the sum of this CacheStats and other.

Note

the values of the metrics are undefined in case of overflow (though it is guaranteed not to throw an exception). If you require specific handling, we recommend implementing your own stats collector.

Since
11.0
requestCountback to summary
public long requestCount()

Returns the number of times Cache lookup methods have returned either a cached or uncached value. This is defined as hitCount + missCount.

Note

the values of the metrics are undefined in case of overflow (though it is guaranteed not to throw an exception). If you require specific handling, we recommend implementing your own stats collector.

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override
totalLoadTimeback to summary
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 or loadExceptionCount is incremented.

Annotations
@SuppressWarnings:GoodTime