private CacheBuilder<Object, Object> createCacheBuilder() { return CacheBuilder.newBuilder().recordStats(); }
@Inject public ExpressionCompiler(Metadata metadata, PageFunctionCompiler pageFunctionCompiler) { requireNonNull(metadata, "metadata is null"); this.pageFunctionCompiler = requireNonNull(pageFunctionCompiler, "pageFunctionCompiler is null"); this.cursorProcessors = CacheBuilder.newBuilder() .recordStats() .maximumSize(1000) .build(CacheLoader.from(key -> compile(key.getFilter(), key.getProjections(), new CursorProcessorCompiler(metadata), CursorProcessor.class))); this.cacheStatsMBean = new CacheStatsMBean(cursorProcessors); }
public GuavaCacheWrapper(MetricRegistry registry) { cache = CacheBuilder.newBuilder() .expireAfterWrite(1, TimeUnit.SECONDS) .maximumSize(1000) .concurrencyLevel(8) .recordStats() .build(); MetricUtils.safelyRegisterAll(registry, new CacheStatsSet(MetricRegistry.name(MongoDbAuthorizationCacheManager.class, "cache"), cache)); }
@Override public LoadingCache<Object, Object> apply(CacheBuilder<Object, Object> builder) { return builder.recordStats().build(identityLoader()); } });
@Inject public EtagService(SidecarPluginConfiguration pluginConfiguration, MetricRegistry metricRegistry, EventBus eventBus, ClusterEventBus clusterEventBus) { this.metricRegistry = metricRegistry; this.eventBus = eventBus; this.clusterEventBus = clusterEventBus; Duration cacheTime = pluginConfiguration.getCacheTime(); cache = CacheBuilder.newBuilder() .recordStats() .expireAfterWrite(cacheTime.getQuantity(), cacheTime.getUnit()) .maximumSize(pluginConfiguration.getCacheMaxSize()) .build(); }
public void testParse_recordStats() { CacheBuilderSpec spec = parse("recordStats"); assertTrue(spec.recordStats); assertCacheBuilderEquivalence(CacheBuilder.newBuilder().recordStats(), CacheBuilder.from(spec)); }
public void testBulkLoadInterruptedException() { Exception e = new InterruptedException(); CacheLoader<Object, Object> loader = exceptionLoader(e); LoadingCache<Object, Object> cache = CacheBuilder.newBuilder().recordStats().build(bulkLoader(loader)); CacheStats stats = cache.stats(); assertEquals(0, stats.missCount()); assertEquals(0, stats.loadSuccessCount()); assertEquals(0, stats.loadExceptionCount()); assertEquals(0, stats.hitCount()); try { cache.getAll(asList(new Object())); fail(); } catch (ExecutionException expected) { assertThat(expected).hasCauseThat().isSameAs(e); } assertTrue(currentThread().interrupted()); stats = cache.stats(); assertEquals(1, stats.missCount()); assertEquals(0, stats.loadSuccessCount()); assertEquals(1, stats.loadExceptionCount()); assertEquals(0, stats.hitCount()); }
public void testBulkLoadCheckedException() { Exception e = new Exception(); CacheLoader<Object, Object> loader = exceptionLoader(e); LoadingCache<Object, Object> cache = CacheBuilder.newBuilder().recordStats().build(bulkLoader(loader)); CacheStats stats = cache.stats(); assertEquals(0, stats.missCount()); assertEquals(0, stats.loadSuccessCount()); assertEquals(0, stats.loadExceptionCount()); assertEquals(0, stats.hitCount()); try { cache.getAll(asList(new Object())); fail(); } catch (ExecutionException expected) { assertThat(expected).hasCauseThat().isSameAs(e); } stats = cache.stats(); assertEquals(1, stats.missCount()); assertEquals(0, stats.loadSuccessCount()); assertEquals(1, stats.loadExceptionCount()); assertEquals(0, stats.hitCount()); }
public void testBulkLoadUncheckedException() throws ExecutionException { Exception e = new RuntimeException(); CacheLoader<Object, Object> loader = exceptionLoader(e); LoadingCache<Object, Object> cache = CacheBuilder.newBuilder().recordStats().build(bulkLoader(loader)); CacheStats stats = cache.stats(); assertEquals(0, stats.missCount()); assertEquals(0, stats.loadSuccessCount()); assertEquals(0, stats.loadExceptionCount()); assertEquals(0, stats.hitCount()); try { cache.getAll(asList(new Object())); fail(); } catch (UncheckedExecutionException expected) { assertThat(expected).hasCauseThat().isSameAs(e); } stats = cache.stats(); assertEquals(1, stats.missCount()); assertEquals(0, stats.loadSuccessCount()); assertEquals(1, stats.loadExceptionCount()); assertEquals(0, stats.hitCount()); }
public void testBulkLoadError() throws ExecutionException { Error e = new Error(); CacheLoader<Object, Object> loader = errorLoader(e); LoadingCache<Object, Object> cache = CacheBuilder.newBuilder().recordStats().build(bulkLoader(loader)); CacheStats stats = cache.stats(); assertEquals(0, stats.missCount()); assertEquals(0, stats.loadSuccessCount()); assertEquals(0, stats.loadExceptionCount()); assertEquals(0, stats.hitCount()); try { cache.getAll(asList(new Object())); fail(); } catch (ExecutionError expected) { assertThat(expected).hasCauseThat().isSameAs(e); } stats = cache.stats(); assertEquals(1, stats.missCount()); assertEquals(0, stats.loadSuccessCount()); assertEquals(1, stats.loadExceptionCount()); assertEquals(0, stats.hitCount()); }
public void testBulkLoadNull() throws ExecutionException { LoadingCache<Object, Object> cache = CacheBuilder.newBuilder().recordStats().build(bulkLoader(constantLoader(null))); CacheStats stats = cache.stats(); assertEquals(0, stats.missCount()); assertEquals(0, stats.loadSuccessCount()); assertEquals(0, stats.loadExceptionCount()); assertEquals(0, stats.hitCount()); try { cache.getAll(asList(new Object())); fail(); } catch (InvalidCacheLoadException expected) { } stats = cache.stats(); assertEquals(1, stats.missCount()); assertEquals(0, stats.loadSuccessCount()); assertEquals(1, stats.loadExceptionCount()); assertEquals(0, stats.hitCount()); }
public void testBulkLoadNullMap() throws ExecutionException { LoadingCache<Object, Object> cache = CacheBuilder.newBuilder() .recordStats() .build( new CacheLoader<Object, Object>() {
public void testGetAllPresent() { Cache<Integer, Integer> cache = CacheBuilder.newBuilder().recordStats().build(); CacheStats stats = cache.stats(); assertEquals(0, stats.missCount());
LoadingCache<Object, Object> cache = CacheBuilder.newBuilder().recordStats().build(loader); Object key = new Object(); CacheStats stats = cache.stats();
LoadingCache<Object, Object> cache = CacheBuilder.newBuilder().recordStats().build(loader); Object key = new Object(); CacheStats stats = cache.stats();
LoadingCache<Object, Object> cache = CacheBuilder.newBuilder().recordStats().build(loader); Object key = new Object(); CacheStats stats = cache.stats();
LoadingCache<Object, Object> cache = CacheBuilder.newBuilder().recordStats().build(loader); Object key = new Object(); CacheStats stats = cache.stats();
public void testBulkLoad_loadAll() throws ExecutionException { IdentityLoader<Integer> backingLoader = identityLoader(); CacheLoader<Integer, Integer> loader = bulkLoader(backingLoader); LoadingCache<Integer, Integer> cache = CacheBuilder.newBuilder().recordStats().build(loader); CacheStats stats = cache.stats(); assertEquals(0, stats.missCount());
LoadingCache<Object, Object> cache = CacheBuilder.newBuilder().recordStats().build(loader); Object key = new Object(); CacheStats stats = cache.stats();
public void testRecordStats() { CacheBuilder<Object, Object> builder = createCacheBuilder().recordStats().concurrencyLevel(1).maximumSize(2); LocalLoadingCache<Object, Object> cache = makeCache(builder, identityLoader()); assertEquals(0, cache.stats().hitCount()); assertEquals(0, cache.stats().missCount()); Object one = new Object(); cache.getUnchecked(one); assertEquals(0, cache.stats().hitCount()); assertEquals(1, cache.stats().missCount()); cache.getUnchecked(one); assertEquals(1, cache.stats().hitCount()); assertEquals(1, cache.stats().missCount()); Object two = new Object(); cache.getUnchecked(two); assertEquals(1, cache.stats().hitCount()); assertEquals(2, cache.stats().missCount()); Object three = new Object(); cache.getUnchecked(three); assertEquals(1, cache.stats().hitCount()); assertEquals(3, cache.stats().missCount()); }