These code examples were ranked by Codota’s semantic indexing as the best open source examples for Cache stats method.
protected abstract Cache<?, ?> getCache(); private CacheStats getCachedCacheStats() { if (cache == null || nextLoad <= System.currentTimeMillis()) { cache = getCache(); cacheStats = cache.stats(); size = cache.size(); nextLoad = System.currentTimeMillis() + loadIterval; } return cacheStats; } public final long getLoadIterval() { return loadIterval; } /** * Number of milliseconds between calls to {@link CharacterDataEventImpl#getEventCacheStats()} */
this.cache = cache; } @Override public void addMetrics(MetricTreeObject tree) { long size = cache.size(); CacheStats stats = cache.stats(); MetricTreeObject subtree = tree.getSubtree(key); subtree.addInt("size", size); subtree.addInt("evictionCount", stats.evictionCount()); subtree.addInt("hitCount", stats.hitCount()); subtree.addInt("loadCount", stats.loadCount()); subtree.addInt("loadExceptionCount", stats.loadExceptionCount()); subtree.addInt("loadSuccessCount", stats.loadSuccessCount()); subtree.addInt("missCount", stats.missCount()); subtree.addInt("requestCount", stats.requestCount()); subtree.addInt("totalLoadTime", stats.totalLoadTime());
return cache.asMap().keySet(); } @Override public long getCacheHits() { return cache.stats().hitCount(); } @Override public long getCacheMisses() { return cache.stats().missCount(); } }
cache.invalidateAll(toInvalidate); assertEquals(toInvalidate, invalidated); } public void testEmptySimpleStats() { StatsCounter counter = new SimpleStatsCounter(); CacheStats stats = counter.snapshot(); assertEquals(0, stats.requestCount()); assertEquals(0, stats.hitCount()); assertEquals(1.0, stats.hitRate()); assertEquals(0, stats.missCount()); assertEquals(0.0, stats.missRate()); assertEquals(0, stats.loadSuccessCount()); assertEquals(0, stats.loadExceptionCount()); assertEquals(0, stats.loadCount()); assertEquals(0, stats.totalLoadTime()); assertEquals(0.0, stats.averageLoadPenalty()); assertEquals(0, stats.evictionCount()); }
* Returns a set of statistics about the cache contents and usage. * * @return a set of statistics about the cache contents and usage */ public CacheStats stats() { return cache.stats(); } /** * Exception thrown by {@link CacheLoader#load(Object)} when the authenticator returns {@link Optional#empty()}. * This is used to prevent caching of invalid credentials. */ private static class InvalidCredentialsException extends Exception { } }
public String getName() { return name; } private com.google.common.cache.CacheStats stats() { return cache.stats().minus(lastSnapshot); } static String timeInWords(long nanos) { long millis = TimeUnit.NANOSECONDS.toMillis(nanos); return String.format("%d min, %d sec", TimeUnit.MILLISECONDS.toMinutes(millis), TimeUnit.MILLISECONDS.toSeconds(millis) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(millis)) ); } }