@GwtCompatible public final class CacheStats extends Object
Cache
. Instances of this class are immutable.
Cache statistics are incremented according to the following rules:
hitCount
is incremented.
missCount
and loadSuccessCount
are
incremented, and the total loading time, in nanoseconds, is added to totalLoadTime
.
missCount
and loadExceptionCount
are incremented, and the total loading time, in nanoseconds, is added to
totalLoadTime
.
missCount
.
evictionCount
is incremented.
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)
.
Constructor and Description |
---|
CacheStats(long hitCount,
long missCount,
long loadSuccessCount,
long loadExceptionCount,
long totalLoadTime,
long evictionCount)
Constructs a new
CacheStats instance. |
Modifier and Type | Method and Description |
---|---|
double |
averageLoadPenalty()
Returns the average time spent loading new values.
|
boolean |
equals(Object object)
Indicates whether some other object is "equal to" this one.
|
long |
evictionCount()
Returns the number of times an entry has been evicted.
|
int |
hashCode()
Returns a hash code value for the object.
|
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()
Returns a string representation of the object.
|
long |
totalLoadTime()
Returns the total number of nanoseconds the cache has spent loading new values.
|
public CacheStats(long hitCount, long missCount, long loadSuccessCount, long loadExceptionCount, long totalLoadTime, long evictionCount)
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.
public long requestCount()
Cache
lookup methods have returned either a cached or
uncached value. This is defined as hitCount + missCount
.public long hitCount()
Cache
lookup methods have returned a cached value.public double hitRate()
hitCount / requestCount
, or 1.0
when requestCount == 0
. Note that
hitRate + missRate =~ 1.0
.public long missCount()
public double missRate()
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.public long loadCount()
Cache
lookup methods attempted to load new
values. This includes both successful load operations, as well as those that threw exceptions.
This is defined as loadSuccessCount + loadExceptionCount
.public long loadSuccessCount()
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
.public long loadExceptionCount()
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
.public double loadExceptionRate()
loadExceptionCount / (loadSuccessCount + loadExceptionCount)
, or 0.0
when
loadSuccessCount + loadExceptionCount == 0
.public long totalLoadTime()
loadSuccessCount
or loadExceptionCount
is incremented.public double averageLoadPenalty()
totalLoadTime / (loadSuccessCount + loadExceptionCount)
.public long evictionCount()
public CacheStats minus(CacheStats other)
CacheStats
representing the difference between this CacheStats
and other
. Negative values, which aren't supported by CacheStats
will be
rounded up to zero.public CacheStats plus(CacheStats other)
CacheStats
representing the sum of this CacheStats
and
other
.public int hashCode()
java.lang.Object
HashMap
.
The general contract of hashCode
is:
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.
equals(Object)
method, then calling the hashCode
method on each of
the two objects must produce the same integer result.
Object.equals(java.lang.Object)
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.
As much as is reasonably practical, the hashCode method defined by
class Object
does return distinct integers for distinct
objects. (This is typically implemented by converting the internal
address of the object into an integer, but this implementation
technique is not required by the
Java™ programming language.)
hashCode
in class Object
Object.equals(java.lang.Object)
,
System.identityHashCode(java.lang.Object)
public boolean equals(@Nullable Object object)
java.lang.Object
The equals
method implements an equivalence relation
on non-null object references:
x
, x.equals(x)
should return
true
.
x
and y
, x.equals(y)
should return true
if and only if
y.equals(x)
returns true
.
x
, y
, and z
, if
x.equals(y)
returns true
and
y.equals(z)
returns true
, then
x.equals(z)
should return true
.
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.
x
,
x.equals(null)
should return false
.
The equals
method for class Object
implements
the most discriminating possible equivalence relation on objects;
that is, for any non-null reference values x
and
y
, this method returns true
if and only
if x
and y
refer to the same object
(x == y
has the value true
).
Note that it is generally necessary to override the hashCode
method whenever this method is overridden, so as to maintain the
general contract for the hashCode
method, which states
that equal objects must have equal hash codes.
equals
in class Object
object
- the reference object with which to compare.true
if this object is the same as the obj
argument; false
otherwise.Object.hashCode()
,
HashMap
public String toString()
java.lang.Object
toString
method returns a string that
"textually represents" this object. The result should
be a concise but informative representation that is easy for a
person to read.
It is recommended that all subclasses override this method.
The toString
method for class Object
returns a string consisting of the name of the class of which the
object is an instance, the at-sign character `@
', and
the unsigned hexadecimal representation of the hash code of the
object. In other words, this method returns a string equal to the
value of:
getClass().getName() + '@' + Integer.toHexString(hashCode())
Copyright © 2010–2017. All rights reserved.