Class CaffeineCacheMetrics
- All Implemented Interfaces:
io.micrometer.core.instrument.binder.MeterBinder
This implementation utilizes a background thread to refresh the cache statistics (e.g., hit/miss
counts, estimated size, and eviction weight) upon a scrape request. By offloading these
calculations—particularly the aggregation of concurrent LongAdder arrays in
cache.stats() and the traversal of the eviction policy—we prevent blocking the main
request threads (such as Tomcat HTTP threads) during Micrometer scrapes.
If a refresh is already in progress, additional scrape requests will use the currently available metrics and will not spawn additional tasks.
Additionally, if the cache is configured with a weigher that tracks byte sizes (such as with a
CaffeineProxy), this binder exposes a cache.memory.used gauge to accurately
report the total on-heap memory footprint of the cache region.
-
Constructor Summary
ConstructorsConstructorDescriptionCaffeineCacheMetrics(ExecutorService refreshExecutor, com.github.benmanes.caffeine.cache.Cache<?, ?> cache, String name, Iterable<io.micrometer.core.instrument.Tag> tags) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidbindImplementationSpecificMetrics(io.micrometer.core.instrument.MeterRegistry registry) protected Longprotected longhitCount()protected Longstatic CaffeineCacheMetricsmonitor(io.micrometer.core.instrument.MeterRegistry registry, ExecutorService refreshExecutor, com.github.benmanes.caffeine.cache.Cache<?, ?> cache, String name, String... tags) protected longputCount()protected Longsize()Methods inherited from class io.micrometer.core.instrument.binder.cache.CacheMeterBinder
bindTo, getCache, getTagsWithCacheName
-
Constructor Details
-
CaffeineCacheMetrics
public CaffeineCacheMetrics(ExecutorService refreshExecutor, com.github.benmanes.caffeine.cache.Cache<?, ?> cache, String name, Iterable<io.micrometer.core.instrument.Tag> tags)
-
-
Method Details
-
monitor
public static CaffeineCacheMetrics monitor(io.micrometer.core.instrument.MeterRegistry registry, ExecutorService refreshExecutor, com.github.benmanes.caffeine.cache.Cache<?, ?> cache, String name, String... tags) -
size
- Specified by:
sizein classio.micrometer.core.instrument.binder.cache.CacheMeterBinder
-
hitCount
protected long hitCount()- Specified by:
hitCountin classio.micrometer.core.instrument.binder.cache.CacheMeterBinder
-
missCount
- Specified by:
missCountin classio.micrometer.core.instrument.binder.cache.CacheMeterBinder
-
evictionCount
- Specified by:
evictionCountin classio.micrometer.core.instrument.binder.cache.CacheMeterBinder
-
putCount
protected long putCount()- Specified by:
putCountin classio.micrometer.core.instrument.binder.cache.CacheMeterBinder
-
bindImplementationSpecificMetrics
protected void bindImplementationSpecificMetrics(io.micrometer.core.instrument.MeterRegistry registry) - Specified by:
bindImplementationSpecificMetricsin classio.micrometer.core.instrument.binder.cache.CacheMeterBinder
-