public static final class AbstractCache.SimpleStatsCounter extends Object implements AbstractCache.StatsCounter
A thread-safe AbstractCache.StatsCounter implementation for use by Cache implementors.
| Constructor and Description |
|---|
SimpleStatsCounter()
Constructs an instance with all counts initialized to zero.
|
| Modifier and Type | Method and Description |
|---|---|
void |
incrementBy(AbstractCache.StatsCounter other)
Increments all counters by the values in
other. |
void |
recordEviction()
Records the eviction of an entry from the cache.
|
void |
recordHits(int count)
Records cache hits.
|
void |
recordLoadException(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.
|
public SimpleStatsCounter()
Constructs an instance with all counts initialized to zero.
public void recordHits(int count)
AbstractCache.StatsCounterRecords cache hits. This should be called when a cache request returns a cached value.
recordHits in interface AbstractCache.StatsCountercount - the number of hits to recordpublic void recordMisses(int count)
AbstractCache.StatsCounterRecords 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 recordLoadException and multiple calls to this method, despite all being served by the results of a single load operation.
recordMisses in interface AbstractCache.StatsCountercount - the number of misses to recordpublic void recordLoadSuccess(long loadTime)
AbstractCache.StatsCounterRecords 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 to AbstractCache.StatsCounter.recordMisses(int), this method should only be called by the loading thread.
recordLoadSuccess in interface AbstractCache.StatsCounterloadTime - the number of nanoseconds the cache spent computing or retrieving the new valuepublic void recordLoadException(long loadTime)
AbstractCache.StatsCounterRecords the failed load of a new entry. This should be called when a cache request causes an entry to be loaded, but an exception is thrown while loading the entry. In contrast to AbstractCache.StatsCounter.recordMisses(int), this method should only be called by the loading thread.
recordLoadException in interface AbstractCache.StatsCounterloadTime - the number of nanoseconds the cache spent computing or retrieving the new value prior to an exception being thrownpublic void recordEviction()
AbstractCache.StatsCounterRecords 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.
recordEviction in interface AbstractCache.StatsCounterpublic CacheStats snapshot()
AbstractCache.StatsCounterReturns a snapshot of this counter’s values. Note that this may be an inconsistent view, as it may be interleaved with update operations.
snapshot in interface AbstractCache.StatsCounterpublic void incrementBy(AbstractCache.StatsCounter other)
Increments all counters by the values in other.