/** * Returns a new {@code CacheStats} representing the sum of this {@code CacheStats} and {@code * other}. * * @since 11.0 */ public CacheStats plus(CacheStats other) { return new CacheStats( hitCount + other.hitCount, missCount + other.missCount, loadSuccessCount + other.loadSuccessCount, loadExceptionCount + other.loadExceptionCount, totalLoadTime + other.totalLoadTime, evictionCount + other.evictionCount); }
/** * Returns the ratio of cache requests which were hits. This is defined as {@code hitCount / * requestCount}, or {@code 1.0} when {@code requestCount == 0}. Note that {@code hitRate + * missRate =~ 1.0}. */ public double hitRate() { long requestCount = requestCount(); return (requestCount == 0) ? 1.0 : (double) hitCount / requestCount; }
/** Increments all counters by the values in {@code other}. */ public void incrementBy(StatsCounter other) { CacheStats otherStats = other.snapshot(); hitCount.add(otherStats.hitCount()); missCount.add(otherStats.missCount()); loadSuccessCount.add(otherStats.loadSuccessCount()); loadExceptionCount.add(otherStats.loadExceptionCount()); totalLoadTime.add(otherStats.totalLoadTime()); evictionCount.add(otherStats.evictionCount()); } }
/** * Returns a new {@code CacheStats} representing the difference between this {@code CacheStats} * and {@code other}. Negative values, which aren't supported by {@code CacheStats} will be * rounded up to zero. */ public CacheStats minus(CacheStats other) { return new CacheStats( Math.max(0, hitCount - other.hitCount), Math.max(0, missCount - other.missCount), Math.max(0, loadSuccessCount - other.loadSuccessCount), Math.max(0, loadExceptionCount - other.loadExceptionCount), Math.max(0, totalLoadTime - other.totalLoadTime), Math.max(0, evictionCount - other.evictionCount)); }
/** * Returns the ratio of cache requests which were misses. This is defined as {@code missCount / * requestCount}, or {@code 0.0} when {@code requestCount == 0}. Note that {@code hitRate + * 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 that {@code missCount >= * loadSuccessCount + loadExceptionCount}. Multiple concurrent misses for the same key will result * in a single load operation. */ public double missRate() { long requestCount = requestCount(); return (requestCount == 0) ? 0.0 : (double) missCount / requestCount; }
@Override public CacheStats snapshot() { return new CacheStats( hitCount.sum(), missCount.sum(), loadSuccessCount.sum(), loadExceptionCount.sum(), totalLoadTime.sum(), evictionCount.sum()); }