diff --git a/README.md b/README.md index 195de6270..21a15c967 100644 --- a/README.md +++ b/README.md @@ -88,12 +88,12 @@ import com.palantir.tritium.metrics.caffeine.CacheStats; TaggedMetricRegistry taggedMetricRegistry = ... CacheStats cacheStats = CacheStats.of(taggedMetricRegistry, "unique-cache-name"); Cache cache = cacheStats.register(Caffeine.newBuilder() - .recordStats(cacheStats.recorder()) + .recordStats(cacheStats) .build()); CacheStats loadingCacheStats = CacheStats.of(taggedMetricRegistry, "unique-loading-cache-name"); LoadingCache loadingCache = loadingCacheStats.register(Caffeine.newBuilder() - .recordStats(loadingCacheStats.recorder()) + .recordStats(loadingCacheStats) .build(key::length)); ``` diff --git a/tritium-caffeine/src/main/java/com/palantir/tritium/metrics/caffeine/CacheStats.java b/tritium-caffeine/src/main/java/com/palantir/tritium/metrics/caffeine/CacheStats.java index 3db6413fb..36f102d00 100644 --- a/tritium-caffeine/src/main/java/com/palantir/tritium/metrics/caffeine/CacheStats.java +++ b/tritium-caffeine/src/main/java/com/palantir/tritium/metrics/caffeine/CacheStats.java @@ -31,7 +31,7 @@ import java.util.function.Supplier; import org.checkerframework.checker.index.qual.NonNegative; -public final class CacheStats implements StatsCounter { +public final class CacheStats implements StatsCounter, Supplier { private final CacheMetrics metrics; private final String name; private final Counter hitCounter; @@ -112,8 +112,9 @@ public LoadingCache register(LoadingCache cache) { return (LoadingCache) register((Cache) cache); } - public Supplier recorder() { - return () -> this; + @Override + public StatsCounter get() { + return this; } @Override diff --git a/tritium-caffeine/src/test/java/com/palantir/tritium/metrics/caffeine/CaffeineCacheStatsTest.java b/tritium-caffeine/src/test/java/com/palantir/tritium/metrics/caffeine/CaffeineCacheStatsTest.java index c10fbb6b2..fd280df9b 100644 --- a/tritium-caffeine/src/test/java/com/palantir/tritium/metrics/caffeine/CaffeineCacheStatsTest.java +++ b/tritium-caffeine/src/test/java/com/palantir/tritium/metrics/caffeine/CaffeineCacheStatsTest.java @@ -214,10 +214,8 @@ void registerCacheWithoutRecordingStatsTagged() { @Test void registerTaggedMetrics() { CacheStats cacheStats = CacheStats.of(taggedMetricRegistry, "test"); - Cache cache = cacheStats.register(Caffeine.newBuilder() - .recordStats(cacheStats.recorder()) - .maximumSize(2) - .build()); + Cache cache = cacheStats.register( + Caffeine.newBuilder().recordStats(cacheStats).maximumSize(2).build()); assertThat(taggedMetricRegistry.getMetrics().keySet()) .extracting(MetricName::safeName) .contains( @@ -264,10 +262,8 @@ void registerTaggedMetrics() { @Test void registerLoadingTaggedMetrics() { CacheStats cacheStats = CacheStats.of(taggedMetricRegistry, "test"); - LoadingCache cache = cacheStats.register(Caffeine.newBuilder() - .recordStats(cacheStats.recorder()) - .maximumSize(2) - .build(mapping::apply)); + LoadingCache cache = cacheStats.register( + Caffeine.newBuilder().recordStats(cacheStats).maximumSize(2).build(mapping::apply)); assertThat(taggedMetricRegistry.getMetrics().keySet()) .extracting(MetricName::safeName) .contains(