Package org.atlanmod.commons.cache
Class CacheStats
- java.lang.Object
-
- org.atlanmod.commons.cache.CacheStats
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedCacheStats(long hitCount, long missCount, long loadSuccessCount, long loadFailureCount, long totalLoadTime, long evictionCount)Constructs a newCacheStats.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description doubleaverageLoadPenalty()Returns the average time spent loading new values.booleanequals(Object o)longevictionCount()Returns the number of times an entry has been evicted.inthashCode()longhitCount()Returns the number of timesCachelookup methods have returned a cached value.doublehitRate()Returns the ratio of cache requests which were hits.longloadCount()Returns the total number of times thatCachelookup methods attempted to load new values.longloadFailureCount()Returns the number of timesCachelookup methods failed to load a new value, either because no value was found or an exception was thrown while loading.doubleloadFailureRate()Returns the ratio of cache loading attempts which threw exceptions.longloadSuccessCount()Returns the number of timesCachelookup methods have successfully loaded a new value.CacheStatsminus(CacheStats other)Returns a newCacheStatsrepresenting the difference between thisCacheStatsandother.longmissCount()Returns the number of timesCachelookup methods have returned an uncached (newly loaded) value, or null.doublemissRate()Returns the ratio of cache requests which were misses.CacheStatsplus(CacheStats other)Returns a newCacheStatsrepresenting the sum of thisCacheStatsandother.longrequestCount()Returns the number of timesCachelookup methods have returned either a cached or uncached value.StringtoString()DurationtotalLoadTime()Returns the total number of nanoseconds the cache has spent loading new values.
-
-
-
Constructor Detail
-
CacheStats
protected CacheStats(@Nonnegative long hitCount, @Nonnegative long missCount, @Nonnegative long loadSuccessCount, @Nonnegative long loadFailureCount, @Nonnegative long totalLoadTime, @Nonnegative long evictionCount)Constructs a newCacheStats.- Parameters:
hitCount- the number of cache hitsmissCount- the number of cache missesloadSuccessCount- the number of successful cache loadsloadFailureCount- the number of failed cache loadstotalLoadTime- the total load time (success and failure) in nanosecondsevictionCount- the number of entries evicted from the cache
-
-
Method Detail
-
requestCount
@Nonnegative public long requestCount()
Returns the number of timesCachelookup methods have returned either a cached or uncached value. This is defined ashitCount + missCount.- Returns:
- the
hitCount + missCount
-
hitCount
@Nonnegative public long hitCount()
Returns the number of timesCachelookup methods have returned a cached value.- Returns:
- the number of times
Cachelookup methods have returned a cached value
-
hitRate
@Nonnegative public double hitRate()
Returns the ratio of cache requests which were hits. This is defined ashitCount / requestCount, or1.0whenrequestCount == 0. Note thathitRate + missRate =~ 1.0.- Returns:
- the ratio of cache requests which were hits
-
missCount
@Nonnegative public long missCount()
Returns the number of timesCachelookup methods have returned an uncached (newly loaded) value, or null. Multiple concurrent calls toCachelookup methods on an absent value can result in multiple misses, all returning the results of a single cache load operation.- Returns:
- the number of times
Cachelookup methods have returned an uncached (newly loaded) value, ornull
-
missRate
@Nonnegative public double missRate()
Returns the ratio of cache requests which were misses. This is defined asmissCount / requestCount, or0.0whenrequestCount == 0. Note thathitRate + 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 thatmissCount >= loadSuccessCount + loadFailureCount. Multiple concurrent misses for the same key will result in a single load operation.- Returns:
- the ratio of cache requests which were misses
-
loadCount
@Nonnegative public long loadCount()
Returns the total number of times thatCachelookup methods attempted to load new values. This includes both successful load operations, as well as those that threw exceptions. This is defined asloadSuccessCount + loadFailureCount.- Returns:
- the
loadSuccessCount + loadFailureCount
-
loadSuccessCount
@Nonnegative public long loadSuccessCount()
Returns the number of timesCachelookup methods have successfully loaded a new value. This is always incremented in conjunction withmissCount, thoughmissCountis also incremented when an exception is encountered during cache loading (seeloadFailureCount). Multiple concurrent misses for the same key will result in a single load operation.- Returns:
- the number of times
Cachelookup methods have successfully loaded a new value
-
loadFailureCount
@Nonnegative public long loadFailureCount()
Returns the number of timesCachelookup methods failed to load a new value, either because no value was found or an exception was thrown while loading. This is always incremented in conjunction withmissCount, thoughmissCountis also incremented when cache loading completes successfully (seeloadSuccessCount). Multiple concurrent misses for the same key will result in a single load operation.- Returns:
- the number of times
Cachelookup methods failed to load a new value
-
loadFailureRate
@Nonnegative public double loadFailureRate()
Returns the ratio of cache loading attempts which threw exceptions. This is defined asloadFailureCount / (loadSuccessCount + loadFailureCount), or0.0whenloadSuccessCount + loadFailureCount == 0.- Returns:
- the ratio of cache loading attempts which threw exceptions
-
totalLoadTime
@Nonnegative public Duration totalLoadTime()
Returns the total number of nanoseconds the cache has spent loading new values. This can be used to calculate the miss penalty. This value is increased every timeloadSuccessCountorloadFailureCountis incremented.- Returns:
- the total number of nanoseconds the cache has spent loading new values
-
averageLoadPenalty
@Nonnegative public double averageLoadPenalty()
Returns the average time spent loading new values. This is defined astotalLoadTime / (loadSuccessCount + loadFailureCount).- Returns:
- the average time spent loading new values
-
evictionCount
@Nonnegative public long evictionCount()
Returns the number of times an entry has been evicted. This count does not include manualCache.invalidate(K).- Returns:
- the number of times an entry has been evicted
-
minus
@Nonnull public CacheStats minus(CacheStats other)
Returns a newCacheStatsrepresenting the difference between thisCacheStatsandother. Negative values, which aren't supported byCacheStatswill be rounded up to zero.- Parameters:
other- the statistics to subtract with- Returns:
- the difference between this instance and
other
-
plus
@Nonnull public CacheStats plus(CacheStats other)
Returns a newCacheStatsrepresenting the sum of thisCacheStatsandother.- Parameters:
other- the statistics to add with- Returns:
- the sum of the statistics
-
-