public interface StatsCounter
Cache
for presentation by
Cache.stats()
. This is solely intended for consumption by Cache
implementors.Modifier and Type | Method and Description |
---|---|
static @NonNull StatsCounter |
disabledStatsCounter()
Returns an accumulator that does not record any cache events.
|
static @NonNull StatsCounter |
guardedStatsCounter(@NonNull StatsCounter statsCounter)
Returns an accumulator that suppresses and logs any exception thrown by the delegate
statsCounter . |
void |
recordEviction()
Deprecated.
Use
recordEviction(int, RemovalCause) instead. This method is
scheduled for removal in version 3.0.0. |
default void |
recordEviction(@NonNegative int weight)
Deprecated.
Use
recordEviction(int, RemovalCause) instead. This method is
scheduled for removal in version 3.0.0. |
default void |
recordEviction(@NonNegative int weight,
RemovalCause cause)
Records the eviction of an entry from the cache.
|
void |
recordHits(@NonNegative int count)
Records cache hits.
|
void |
recordLoadFailure(@NonNegative long loadTime)
Records the failed load of a new entry.
|
void |
recordLoadSuccess(@NonNegative long loadTime)
Records the successful load of a new entry.
|
void |
recordMisses(@NonNegative int count)
Records cache misses.
|
@NonNull CacheStats |
snapshot()
Returns a snapshot of this counter's values.
|
void recordHits(@NonNegative int count)
count
- the number of hits to recordvoid recordMisses(@NonNegative int count)
Cache
lookup methods with the same
key on an absent value should result in a single call to either recordLoadSuccess
or
recordLoadFailure
and multiple calls to this method, despite all being served by the
results of a single load operation.count
- the number of misses to recordvoid recordLoadSuccess(@NonNegative long loadTime)
Cache.get(K, java.util.function.Function<? super K, ? extends V>)
or Map.computeIfAbsent(K, java.util.function.Function<? super K, ? extends V>)
) and
the loading completes successfully. In contrast to recordMisses(int)
, this method should
only be called by the loading thread.loadTime
- the number of nanoseconds the cache spent computing or retrieving the new valuevoid recordLoadFailure(@NonNegative long loadTime)
Cache.get(K, java.util.function.Function<? super K, ? extends V>)
or Map.computeIfAbsent(K, java.util.function.Function<? super K, ? extends V>)
), but
an exception is thrown while loading the entry or the loading function returns null. In
contrast to recordMisses(int)
, this method should only be called by the loading thread.loadTime
- the number of nanoseconds the cache spent computing or retrieving the new value
prior to discovering the value doesn't exist or an exception being thrown@Deprecated void recordEviction()
recordEviction(int, RemovalCause)
instead. This method is
scheduled for removal in version 3.0.0.invalidations
.@Deprecated default void recordEviction(@NonNegative int weight)
recordEviction(int, RemovalCause)
instead. This method is
scheduled for removal in version 3.0.0.invalidations
.weight
- the weight of the evicted entrydefault void recordEviction(@NonNegative int weight, RemovalCause cause)
invalidations
.weight
- the weight of the evicted entrycause
- the reason for which the entry was removed@NonNull CacheStats snapshot()
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.
static @NonNull StatsCounter disabledStatsCounter()
static @NonNull StatsCounter guardedStatsCounter(@NonNull StatsCounter statsCounter)
statsCounter
.statsCounter
- the accumulator to delegate to