Top Description Methods
com.github.benmanes.caffeine.cache.stats

public Interface StatsCounter

Known Direct Implementers
com.github.benmanes.caffeine.cache.stats.ConcurrentStatsCounter, com.github.benmanes.caffeine.cache.stats.DisabledStatsCounter, com.github.benmanes.caffeine.cache.stats.GuardedStatsCounter
Imports
java.util.Map, org.checkerframework.checker.index.qual.NonNegative, com.github.benmanes.caffeine.cache.Cache, .RemovalCause

Accumulates statistics during the operation of a Cache for presentation by Cache#stats. This is solely intended for consumption by Cache implementors.
Author
[email protected] (Ben Manes)

Method Summary

Modifier and TypeMethod and Description
public static StatsCounter

Returns:

an accumulator that does not record metrics
disabledStatsCounter
()

Returns an accumulator that does not record any cache events.

public static StatsCounter

Returns:

an accumulator that suppresses and logs any exception thrown by the delegate
guardedStatsCounter
(StatsCounter
the accumulator to delegate to
statsCounter
)

Returns an accumulator that suppresses and logs any exception thrown by the delegate statsCounter.

public void
recordEviction(@NonNegative int
the weight of the evicted entry
weight
,
RemovalCause
the reason for which the entry was removed
cause
)

Records the eviction of an entry from the cache.

public void
recordHits(@NonNegative int
the number of hits to record
count
)

Records cache hits.

public void
recordLoadFailure(@NonNegative long
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
loadTime
)

Records the failed load of a new entry.

public void
recordLoadSuccess(@NonNegative long
the number of nanoseconds the cache spent computing or retrieving the new value
loadTime
)

Records the successful load of a new entry.

public void
recordMisses(@NonNegative int
the number of misses to record
count
)

Records cache misses.

public CacheStats

Returns:

a snapshot of this counter's values
snapshot
()

Returns a snapshot of this counter's values.

Method Detail

disabledStatsCounterback to summary
public static StatsCounter disabledStatsCounter()

Returns an accumulator that does not record any cache events.

Returns:StatsCounter

an accumulator that does not record metrics

guardedStatsCounterback to summary
public static StatsCounter guardedStatsCounter(StatsCounter statsCounter)

Returns an accumulator that suppresses and logs any exception thrown by the delegate statsCounter.

Parameters
statsCounter:StatsCounter

the accumulator to delegate to

Returns:StatsCounter

an accumulator that suppresses and logs any exception thrown by the delegate

recordEvictionback to summary
public void recordEviction(@NonNegative int weight, RemovalCause cause)

Records the eviction of an entry from the cache. This should only been called when an entry is evicted due to the cache's eviction strategy, and not as a result of manual invalidations.

Parameters
weight:@NonNegative int

the weight of the evicted entry

cause:RemovalCause

the reason for which the entry was removed

recordHitsback to summary
public void recordHits(@NonNegative int count)

Records cache hits. This should be called when a cache request returns a cached value.

Parameters
count:@NonNegative int

the number of hits to record

recordLoadFailureback to summary
public void recordLoadFailure(@NonNegative long loadTime)

Records the failed load of a new entry. This method should be called when a cache request causes an entry to be loaded (such as by Cache#get or Map#computeIfAbsent), but an exception is thrown while loading the entry or the loading function returns null. In contrast to recordMisses, this method should only be called by the loading thread.

Parameters
loadTime:@NonNegative long

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

recordLoadSuccessback to summary
public void recordLoadSuccess(@NonNegative long loadTime)

Records the successful load of a new entry. This method should be called when a cache request causes an entry to be loaded (such as by Cache#get or Map#computeIfAbsent) and the loading completes successfully. In contrast to recordMisses, this method should only be called by the loading thread.

Parameters
loadTime:@NonNegative long

the number of nanoseconds the cache spent computing or retrieving the new value

recordMissesback to summary
public void recordMisses(@NonNegative int count)

Records cache misses. This should be called when a cache request returns a value that was not found in the cache. This method should be called by the loading thread, as well as by threads blocking on the load. Multiple concurrent calls to 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.

Parameters
count:@NonNegative int

the number of misses to record

snapshotback to summary
public CacheStats snapshot()

Returns a snapshot of this counter's values. Note that this may be an inconsistent view, as it may be interleaved with update operations.

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.

Returns:CacheStats

a snapshot of this counter's values