Class CacheStats
java.lang.Object
com.palantir.tritium.metrics.caffeine.CacheStats
- All Implemented Interfaces:
com.github.benmanes.caffeine.cache.stats.StatsCounter, Supplier<com.github.benmanes.caffeine.cache.stats.StatsCounter>
-
Method Summary
Modifier and TypeMethodDescriptioncom.github.benmanes.caffeine.cache.stats.StatsCounterget()static CacheStatsof(com.palantir.tritium.metrics.registry.TaggedMetricRegistry taggedMetricRegistry, @Safe String name) Creates aCacheStatsinstance that can be used to record metrics for Caffeine cache statistics.voidrecordEviction(int weight, com.github.benmanes.caffeine.cache.RemovalCause cause) voidrecordHits(int count) voidrecordLoadFailure(long loadTime) voidrecordLoadSuccess(long loadTime) voidrecordMisses(int count) <K,V> void register(com.github.benmanes.caffeine.cache.Cache<K, V> cache) Registers additional metrics for a Caffeine cache.<K, V, C extends com.github.benmanes.caffeine.cache.Cache<K,V>>
Cregister(Function<CacheStats, C> cacheFactory) Constructs and registers metrics for Caffeine cache statistics.<K, V, C extends com.github.benmanes.caffeine.cache.AsyncCache<K,V>>
CregisterAsync(Function<CacheStats, C> cacheFactory) Constructs and registers metrics for Caffeine cache statistics.com.github.benmanes.caffeine.cache.stats.CacheStatssnapshot()toString()
-
Method Details
-
of
public static CacheStats of(com.palantir.tritium.metrics.registry.TaggedMetricRegistry taggedMetricRegistry, @Safe @Safe String name) Creates aCacheStatsinstance that can be used to record metrics for Caffeine cache statistics.Example usage:
Cache<Integer, String> cache = CacheStats.of(taggedMetricRegistry, "your-cache-name") .register(stats -> Caffeine.newBuilder() .recordStats(stats) .build());- Parameters:
taggedMetricRegistry- tagged metric registry to add cache metricsname- cache name- Returns:
- Caffeine stats instance to register via
Caffeine.recordStats(Supplier).
-
register
public <K,V> void register(com.github.benmanes.caffeine.cache.Cache<K, V> cache) Registers additional metrics for a Caffeine cache.- Parameters:
cache- cache for which to register metrics
-
register
public <K, V, C extends com.github.benmanes.caffeine.cache.Cache<K,V>> C register(Function<CacheStats, C> cacheFactory) Constructs and registers metrics for Caffeine cache statistics.In order to record metrics, the
cacheFactorymust use the providedCacheStatswithCaffeine.recordStats(Supplier))}.Example usage:
Cache<Integer, String> cache = CacheStats.of(taggedMetricRegistry, "your-cache-name") .register(stats -> Caffeine.newBuilder() .recordStats(stats) .build());- Parameters:
cacheFactory- method which will be invoked to construct the cache- Returns:
- the constructed cache instance
-
registerAsync
public <K, V, C extends com.github.benmanes.caffeine.cache.AsyncCache<K,V>> C registerAsync(Function<CacheStats, C> cacheFactory) Constructs and registers metrics for Caffeine cache statistics.In order to record metrics, the
cacheFactorymust use the providedCacheStatswithCaffeine.recordStats(Supplier))}.Example usage:
AsyncCache<Integer, String> cache = CacheStats.of(taggedMetricRegistry, "your-cache-name") .register(stats -> Caffeine.newBuilder() .recordStats(stats) .buildAsync());- Parameters:
cacheFactory- method which will be invoked to construct the cache- Returns:
- the constructed cache instance
-
get
-
recordHits
public void recordHits(int count) - Specified by:
recordHitsin interfacecom.github.benmanes.caffeine.cache.stats.StatsCounter
-
recordMisses
public void recordMisses(int count) - Specified by:
recordMissesin interfacecom.github.benmanes.caffeine.cache.stats.StatsCounter
-
recordLoadSuccess
public void recordLoadSuccess(long loadTime) - Specified by:
recordLoadSuccessin interfacecom.github.benmanes.caffeine.cache.stats.StatsCounter
-
recordLoadFailure
public void recordLoadFailure(long loadTime) - Specified by:
recordLoadFailurein interfacecom.github.benmanes.caffeine.cache.stats.StatsCounter
-
recordEviction
public void recordEviction(int weight, com.github.benmanes.caffeine.cache.RemovalCause cause) - Specified by:
recordEvictionin interfacecom.github.benmanes.caffeine.cache.stats.StatsCounter
-
snapshot
public com.github.benmanes.caffeine.cache.stats.CacheStats snapshot()- Specified by:
snapshotin interfacecom.github.benmanes.caffeine.cache.stats.StatsCounter
-
toString
-