com.github.benmanes.caffeine.cache.Cache.stats()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(8.2k)|赞(0)|评价(0)|浏览(529)

本文整理了Java中com.github.benmanes.caffeine.cache.Cache.stats()方法的一些代码示例,展示了Cache.stats()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Cache.stats()方法的具体详情如下:
包路径:com.github.benmanes.caffeine.cache.Cache
类名称:Cache
方法名:stats

Cache.stats介绍

[英]Returns a current snapshot of this cache's cumulative statistics. All statistics are initialized to zero, and are monotonically increasing over the lifetime of the cache.

Due to the performance penalty of maintaining statistics, some implementations may not record the usage history immediately or at all.
[中]返回此缓存的累积统计信息的当前快照。所有统计信息都初始化为零,并且在缓存的生存期内单调递增。
由于维护统计信息的性能损失,一些实现可能不会立即或根本不记录使用历史记录。

代码示例

代码示例来源:origin: ben-manes/caffeine

public CacheStats stats() {
 return cache.stats();
}

代码示例来源:origin: rapidoid/rapidoid

/**
   * {@inheritDoc}
   */
  @Override
  public CacheStats stats() {
    return new CacheStats(cache.stats(), bypassed);
  }
}

代码示例来源:origin: ben-manes/caffeine

static void printStats(Cache<Long, Long> cache) {
 if (debug) {
  System.out.printf("size %,d requests %,d hit ratio %f%n",
    cache.estimatedSize(), cache.stats().requestCount(), cache.stats().hitRate());
 }
}

代码示例来源:origin: line/armeria

private boolean updateCacheStats(boolean force) {
    final Cache<?, ?> cache = get();
    if (cache == null) {
      return true; // GC'd
    }
    final long currentTimeNanos = ticker.read();
    if (!force) {
      if (currentTimeNanos - lastStatsUpdateTime < UPDATE_INTERVAL_NANOS) {
        return false; // Not GC'd
      }
    }
    cacheStats = cache.stats();
    estimatedSize = cache.estimatedSize();
    // Write the volatile field last so that cacheStats and estimatedSize are visible
    // after reading the volatile field.
    lastStatsUpdateTime = currentTimeNanos;
    return false; // Not GC'd
  }
}

代码示例来源:origin: ben-manes/caffeine

@Override
public CacheStats stats() {
 com.github.benmanes.caffeine.cache.stats.CacheStats stats = cache.stats();
 return new CacheStats(stats.hitCount(), stats.missCount(), stats.loadSuccessCount(),
   stats.loadFailureCount(), stats.totalLoadTime(), stats.evictionCount());
}

代码示例来源:origin: apache/incubator-druid

@Override
public org.apache.druid.client.cache.CacheStats getStats()
{
 final CacheStats stats = cache.stats();
 final long size = cache
   .policy().eviction()
   .map(eviction -> eviction.isWeighted() ? eviction.weightedSize() : OptionalLong.empty())
   .orElse(OptionalLong.empty()).orElse(-1);
 return new org.apache.druid.client.cache.CacheStats(
   stats.hitCount(),
   stats.missCount(),
   cache.estimatedSize(),
   size,
   stats.evictionCount(),
   0,
   stats.loadFailureCount()
 );
}

代码示例来源:origin: ben-manes/caffeine

@CacheSpec
@CheckNoWriter @CheckNoStats
@Test(dataProvider = "caches")
public void stats(Cache<Integer, Integer> cache, CacheContext context) {
 CacheStats stats = cache.stats()
   .plus(new CacheStats(1, 2, 3, 4, 5, 6, 7)
   .minus(new CacheStats(6, 5, 4, 3, 2, 1, 0)));
 assertThat(stats, is(new CacheStats(0, 0, 0, 1, 3, 5, 7)));
 assertThat(cache.policy().isRecordingStats(), is(context.isRecordingStats()));
}

代码示例来源:origin: ben-manes/caffeine

printStats(cache);
assertThat(cache.stats().hitRate(), is(greaterThan(0.99d)));

代码示例来源:origin: apache/incubator-druid

@Override
public void doMonitor(ServiceEmitter emitter)
{
 final CacheStats oldStats = priorStats.get();
 final CacheStats newStats = cache.stats();
 final CacheStats deltaStats = newStats.minus(oldStats);
 final ServiceMetricEvent.Builder builder = ServiceMetricEvent.builder();
 emitter.emit(builder.build("query/cache/caffeine/delta/requests", deltaStats.requestCount()));
 emitter.emit(builder.build("query/cache/caffeine/total/requests", newStats.requestCount()));
 emitter.emit(builder.build("query/cache/caffeine/delta/loadTime", deltaStats.totalLoadTime()));
 emitter.emit(builder.build("query/cache/caffeine/total/loadTime", newStats.totalLoadTime()));
 emitter.emit(builder.build("query/cache/caffeine/delta/evictionBytes", deltaStats.evictionWeight()));
 emitter.emit(builder.build("query/cache/caffeine/total/evictionBytes", newStats.evictionWeight()));
 if (!priorStats.compareAndSet(oldStats, newStats)) {
  // ISE for stack trace
  log.warn(
    new IllegalStateException("Multiple monitors"),
    "Multiple monitors on the same cache causing race conditions and unreliable stats reporting"
  );
 }
}

代码示例来源:origin: apache/accumulo

@Override
public BlockCache.Stats getStats() {
 CacheStats stats = cache.stats();
 return new BlockCache.Stats() {
  @Override
  public long hitCount() {
   return stats.hitCount();
  }
  @Override
  public long requestCount() {
   return stats.requestCount();
  }
 };
}

代码示例来源:origin: ahmetaa/zemberek-nlp

@Override
 public String toString() {
  StringBuilder sb = new StringBuilder();
  long total = staticCacheHits + staticCacheMiss;
  if (total > 0) {
   sb.append(String.format("Static cache(size: %d) Hit rate: %.3f%n",
     staticCache.size(), 1.0 * (staticCacheHits) / (staticCacheHits + staticCacheMiss)));
  }
  sb.append(String.format("Dynamic cache hit rate: %.3f ", dynamicCache.stats().hitRate()));
  return sb.toString();
 }
}

代码示例来源:origin: apache/incubator-druid

Assert.assertNull(cache.get(key2));
Assert.assertEquals(0, cache.getCache().stats().evictionWeight());
Assert.assertNull(cache.get(key1));
Assert.assertArrayEquals(val2, cache.get(key2));
Assert.assertEquals(34, cache.getCache().stats().evictionWeight());

代码示例来源:origin: apache/accumulo

private void logStats() {
 double maxMB = ((double) policy.getMaximum()) / ((double) (1024 * 1024));
 double sizeMB = ((double) policy.weightedSize().getAsLong()) / ((double) (1024 * 1024));
 double freeMB = maxMB - sizeMB;
 log.debug("Cache Size={}MB, Free={}MB, Max={}MB, Blocks={}", sizeMB, freeMB, maxMB,
   cache.estimatedSize());
 log.debug(cache.stats().toString());
}

代码示例来源:origin: apache/metron

/**
 * Performs cache maintenance on both the active and expired caches.
 */
private void cacheMaintenance() {
 activeCache.cleanUp();
 LOG.debug("Active cache maintenance triggered: cacheStats={}, size={}",
     activeCache.stats().toString(), activeCache.estimatedSize());
 expiredCache.cleanUp();
 LOG.debug("Expired cache maintenance triggered: cacheStats={}, size={}",
     expiredCache.stats().toString(), expiredCache.estimatedSize());
}

代码示例来源:origin: apache/metron

if(perfLog.isDebugEnabled() && !cacheStats.isEmpty()) {
 CacheStats before =  cacheStats.get(strategy);
 CacheStats after = concurrencyContext.getCache().stats();
 if(before != null && after != null) {
  CacheStats delta = after.minus(before);

代码示例来源:origin: prometheus/client_java

CacheStats stats = c.getValue().stats();

代码示例来源:origin: apache/metron

/**
 * The cache should continue to hit, even if variables not used in the cached expression change.
 */
@Test
public void testUnrelatedVariableChange() {
 // expect miss
 Object result = execute("TO_UPPER(name)", contextWithCache);
 assertEquals("BLAH", result);
 assertEquals(1, cache.stats().requestCount());
 assertEquals(1, cache.stats().missCount());
 assertEquals(0, cache.stats().hitCount());
 // add an irrelevant variable that is not used in the expression
 fields.put("unrelated_var_1", "true");
 fields.put("unrelated_var_2", 22);
 // still expect a hit
 result = execute("TO_UPPER(name)", contextWithCache);
 assertEquals("BLAH", result);
 assertEquals(2, cache.stats().requestCount());
 assertEquals(1, cache.stats().missCount());
 assertEquals(1, cache.stats().hitCount());
}

代码示例来源:origin: apache/metron

/**
 * Running the same expression multiple times should hit the cache.
 */
@Test
public void testWithCache() {
 Object result = execute("TO_UPPER(name)", contextWithCache);
 assertEquals("BLAH", result);
 assertEquals(1, cache.stats().requestCount());
 assertEquals(1, cache.stats().missCount());
 assertEquals(0, cache.stats().hitCount());
 result = execute("TO_UPPER(name)", contextWithCache);
 assertEquals("BLAH", result);
 assertEquals(2, cache.stats().requestCount());
 assertEquals(1, cache.stats().missCount());
 assertEquals(1, cache.stats().hitCount());
 result = execute("TO_UPPER(name)", contextWithCache);
 assertEquals("BLAH", result);
 assertEquals(3, cache.stats().requestCount());
 assertEquals(1, cache.stats().missCount());
 assertEquals(2, cache.stats().hitCount());
}

代码示例来源:origin: locationtech/geogig

public @Override String toString() {
  long size = L2Cache.estimatedSize();
  long bytes = sizeTracker.size.get();
  long avg = size == 0 ? 0 : bytes / size;
  return String.format("Size: %,d, bytes: %,d, avg: %,d bytes/entry, %s", size, bytes, avg,
      L2Cache.stats());
}

代码示例来源:origin: com.github.ben-manes.caffeine/guava

@Override
public CacheStats stats() {
 com.github.benmanes.caffeine.cache.stats.CacheStats stats = cache.stats();
 return new CacheStats(stats.hitCount(), stats.missCount(), stats.loadSuccessCount(),
   stats.loadFailureCount(), stats.totalLoadTime(), stats.evictionCount());
}

相关文章