Interface StatsCounter
-
- All Known Implementing Classes:
ConcurrentStatsCounter
,DisabledStatsCounter
,GuardedStatsCounter
@ThreadSafe public interface StatsCounter
Accumulates statistics during the operation of aCache
for presentation byCache.stats()
. This is solely intended for consumption byCache
implementors.
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Deprecated Methods Modifier and Type Method Description static StatsCounter
disabledStatsCounter()
Returns an accumulator that does not record any cache events.static StatsCounter
guardedStatsCounter(StatsCounter statsCounter)
Returns an accumulator that suppresses and logs any exception thrown by the delegate statsCounter.void
recordEviction()
Deprecated.UserecordEviction(int)
instead.default void
recordEviction(int weight)
Records the eviction of an entry from the cache.void
recordHits(int count)
Records cache hits.void
recordLoadFailure(long loadTime)
Records the failed load of a new entry.void
recordLoadSuccess(long loadTime)
Records the successful load of a new entry.void
recordMisses(int count)
Records cache misses.CacheStats
snapshot()
Returns a snapshot of this counter's values.
-
-
-
Method Detail
-
recordHits
void recordHits(@Nonnegative int count)
Records cache hits. This should be called when a cache request returns a cached value.- Parameters:
count
- the number of hits to record
-
recordMisses
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 toCache
lookup methods with the same key on an absent value should result in a single call to eitherrecordLoadSuccess
orrecordLoadFailure
and multiple calls to this method, despite all being served by the results of a single load operation.- Parameters:
count
- the number of misses to record
-
recordLoadSuccess
void recordLoadSuccess(@Nonnegative long loadTime)
Records the successful load of a new entry. This should be called when a cache request causes an entry to be loaded, and the loading completes successfully. In contrast torecordMisses(int)
, this method should only be called by the loading thread.- Parameters:
loadTime
- the number of nanoseconds the cache spent computing or retrieving the new value
-
recordLoadFailure
void recordLoadFailure(@Nonnegative long loadTime)
Records the failed load of a new entry. This should be called when a cache request causes an entry to be loaded, but either no value is found or an exception is thrown while loading the entry. In contrast torecordMisses(int)
, this method should only be called by the loading thread.- Parameters:
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
-
recordEviction
@Deprecated void recordEviction()
Deprecated.UserecordEviction(int)
instead. This method is scheduled for removal in version 3.0.0.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 manualinvalidations
.
-
recordEviction
default void recordEviction(int weight)
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 manualinvalidations
.- Parameters:
weight
- the weight of the evicted entry
-
snapshot
@Nonnull 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.- Returns:
- a snapshot of this counter's values
-
disabledStatsCounter
@Nonnull static StatsCounter disabledStatsCounter()
Returns an accumulator that does not record any cache events.- Returns:
- an accumulator that does not record metrics
-
guardedStatsCounter
@Nonnull static StatsCounter guardedStatsCounter(@Nonnull StatsCounter statsCounter)
Returns an accumulator that suppresses and logs any exception thrown by the delegate statsCounter.- Parameters:
statsCounter
- the accumulator to delegate to- Returns:
- an accumulator that suppresses and logs any exception thrown by the delegate
-
-