Java Code Examples for com.github.benmanes.caffeine.cache.stats.CacheStats#evictionCount()
The following examples show how to use
com.github.benmanes.caffeine.cache.stats.CacheStats#evictionCount() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CaffeineMetricSupport.java From armeria with Apache License 2.0 | 5 votes |
private ToDoubleFunction<CaffeineMetrics> func(@Nullable Type type, ToDoubleFunction<CacheReference> valueFunction) { return value -> { double sum = 0; synchronized (cacheRefs) { for (final Iterator<CacheReference> i = cacheRefs.iterator(); i.hasNext();) { final CacheReference ref = i.next(); final boolean garbageCollected = ref.updateCacheStats(); if (!garbageCollected) { sum += valueFunction.applyAsDouble(ref); } else { // Remove the garbage-collected reference from the list to prevent it from // growing infinitely. i.remove(); // Accumulate the stats of the removed reference so the counters do not decrease. // NB: We do not accumulate 'estimatedSize' because it's not a counter but a gauge. final CacheStats stats = ref.cacheStats; statsForGarbageCollected[HIT_COUNT.ordinal()] += stats.hitCount(); statsForGarbageCollected[MISS_COUNT.ordinal()] += stats.missCount(); statsForGarbageCollected[EVICTION_COUNT.ordinal()] += stats.evictionCount(); statsForGarbageCollected[EVICTION_WEIGHT.ordinal()] += stats.evictionWeight(); statsForGarbageCollected[LOAD_SUCCESS_COUNT.ordinal()] += stats.loadSuccessCount(); statsForGarbageCollected[LOAD_FAILURE_COUNT.ordinal()] += stats.loadFailureCount(); statsForGarbageCollected[TOTAL_LOAD_TIME.ordinal()] += stats.totalLoadTime(); } } if (type != null) { // Add the value of the garbage-collected caches. sum += statsForGarbageCollected[type.ordinal()]; } } return sum; }; }
Example 2
Source File: CaffeineImpl.java From RxCache with Apache License 2.0 | 3 votes |
public CacheStatistics getCacheStatistics() { CacheStats cacheStats = cache.stats(); long evictionCount = cacheStats.evictionCount(); long hitCount = cacheStats.hitCount(); long missCount = cacheStats.missCount(); return new CacheStatistics((int)maxSize,putCount.get(),(int)evictionCount,(int)hitCount,(int)missCount); }