Class DefaultCacheStats
- java.lang.Object
-
- com.github.javaparser.symbolsolver.cache.DefaultCacheStats
-
- All Implemented Interfaces:
CacheStats
public class DefaultCacheStats extends Object implements CacheStats
Statistics about the performance of aCache. Instances of this class are immutable.Cache statistics are incremented according to the following rules:
- When a cache lookup encounters an existing cache entry
hitCountis incremented. - When a cache lookup first encounters a missing cache entry, a new entry is loaded.
- After successfully loading an entry
missCountandloadSuccessCountare incremented, and the total loading time, in nanoseconds, is added tototalLoadTime. - When an exception is thrown while loading an entry,
missCountandloadExceptionCountare incremented, and the total loading time, in nanoseconds, is added tototalLoadTime. - Cache lookups that encounter a missing cache entry that is still loading will wait
for loading to complete (whether successful or not) and then increment
missCount.
- After successfully loading an entry
- When an entry is evicted from the cache,
evictionCountis incremented. - No stats are modified when a cache entry is invalidated or manually removed.
- No stats are modified by operations invoked on the asMap view of the cache.
-
-
Constructor Summary
Constructors Constructor Description DefaultCacheStats()Constructs a newICacheStatsinstance.DefaultCacheStats(long hitCount, long missCount, long loadSuccessCount, long loadExceptionCount, long totalLoadTime, long evictionCount)Constructs a newICacheStatsinstance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description doubleaverageLoadPenalty()Returns the average time spent loading new values.booleanequals(Object object)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.longloadExceptionCount()Returns the number of timesCachelookup methods threw an exception while loading a new value.doubleloadExceptionRate()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 newICacheStatsrepresenting the difference between thisICacheStatsandother.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 newICacheStatsrepresenting the sum of thisICacheStatsandother.longrequestCount()Returns the number of timesCachelookup methods have returned either a cached or uncached value.StringtoString()longtotalLoadTime()Returns the total number of nanoseconds the cache has spent loading new values.
-
-
-
Constructor Detail
-
DefaultCacheStats
public DefaultCacheStats()
Constructs a newICacheStatsinstance.
-
DefaultCacheStats
public DefaultCacheStats(long hitCount, long missCount, long loadSuccessCount, long loadExceptionCount, long totalLoadTime, long evictionCount)Constructs a newICacheStatsinstance.
-
-
Method Detail
-
requestCount
public long requestCount()
Returns the number of timesCachelookup methods have returned either a cached or uncached value. This is defined ashitCount + missCount.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.
- Specified by:
requestCountin interfaceCacheStats
-
hitCount
public long hitCount()
Returns the number of timesCachelookup methods have returned a cached value.- Specified by:
hitCountin interfaceCacheStats
-
hitRate
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.- Specified by:
hitRatein interfaceCacheStats
-
missCount
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.- Specified by:
missCountin interfaceCacheStats
-
missRate
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 + loadExceptionCount. Multiple concurrent misses for the same key will result in a single load operation.- Specified by:
missRatein interfaceCacheStats
-
loadCount
public long loadCount()
Returns the total number of times thatCachelookup methods attempted to load new values. This includes both successful load operations and those that threw exceptions. This is defined asloadSuccessCount + loadExceptionCount.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.
- Specified by:
loadCountin interfaceCacheStats
-
loadSuccessCount
public long loadSuccessCount()
Returns the number of timesCachelookup methods have successfully loaded a new value. This is usually incremented in conjunction withmissCount, thoughmissCountis also incremented when an exception is encountered during cache loading (seeloadExceptionCount). Multiple concurrent misses for the same key will result in a single load operation. This may be incremented not in conjunction withmissCountif the load occurs as a result of a refresh or if the cache loader returned more items than was requested.missCountmay also be incremented not in conjunction with this (norloadExceptionCount) on calls togetIfPresent.- Specified by:
loadSuccessCountin interfaceCacheStats
-
loadExceptionCount
public long loadExceptionCount()
Returns the number of timesCachelookup methods threw an exception while loading a new value. This is usually 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. This may be incremented not in conjunction withmissCountif the load occurs as a result of a refresh or if the cache loader returned more items than was requested.missCountmay also be incremented not in conjunction with this (norloadSuccessCount) on calls togetIfPresent.- Specified by:
loadExceptionCountin interfaceCacheStats
-
loadExceptionRate
public double loadExceptionRate()
Returns the ratio of cache loading attempts which threw exceptions. This is defined asloadExceptionCount / (loadSuccessCount + loadExceptionCount), or0.0whenloadSuccessCount + loadExceptionCount == 0.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.
- Specified by:
loadExceptionRatein interfaceCacheStats
-
totalLoadTime
public long 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 timeloadSuccessCountorloadExceptionCountis incremented.- Specified by:
totalLoadTimein interfaceCacheStats
-
averageLoadPenalty
public double averageLoadPenalty()
Returns the average time spent loading new values. This is defined astotalLoadTime / (loadSuccessCount + loadExceptionCount).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.
- Specified by:
averageLoadPenaltyin interfaceCacheStats
-
evictionCount
public long evictionCount()
Returns the number of times an entry has been evicted. This count does not include manual invalidations.- Specified by:
evictionCountin interfaceCacheStats
-
minus
public CacheStats minus(CacheStats other)
Returns a newICacheStatsrepresenting the difference between thisICacheStatsandother. Negative values, which aren't supported byICacheStatswill be rounded up to zero.- Specified by:
minusin interfaceCacheStats
-
plus
public CacheStats plus(CacheStats other)
Returns a newICacheStatsrepresenting the sum of thisICacheStatsandother.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.
- Specified by:
plusin interfaceCacheStats- Since:
- 11.0
-
equals
public boolean equals(@CheckForNull Object object)
-
-