Class CacheMeterBinder<C>
java.lang.Object
io.micrometer.core.instrument.binder.cache.CacheMeterBinder<C>
- All Implemented Interfaces:
MeterBinder
- Direct Known Subclasses:
CaffeineCacheMetrics
,EhCache2Metrics
,GuavaCacheMetrics
,HazelcastCacheMetrics
,JCacheMetrics
@NonNullApi
@NonNullFields
public abstract class CacheMeterBinder<C>
extends Object
implements MeterBinder
A common base class for cache metrics that ensures that all caches are instrumented
with the same basic set of metrics while allowing for additional detail that is
specific to an individual implementation.
Having this common base set of metrics ensures that you can reason about basic cache performance in a dimensional slice that spans different cache implementations in your application.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected abstract void
Bind detailed metrics that are particular to the cache implementation, e.g.final void
bindTo
(MeterRegistry registry) protected abstract Long
protected C
getCache()
protected abstract long
hitCount()
protected abstract Long
protected abstract long
putCount()
The put mechanism is unimportant - this count applies to entries added to the cache according to a pre-defined load function such as exists in Guava/Caffeine caches as well as manual puts.protected abstract Long
size()
MOST cache implementations provide a means of retrieving the number of entries.
-
Constructor Details
-
CacheMeterBinder
-
-
Method Details
-
getCache
-
bindTo
- Specified by:
bindTo
in interfaceMeterBinder
-
size
MOST cache implementations provide a means of retrieving the number of entries. Even if- Returns:
- Total number of cache entries. This value may go up or down with puts,
removes, and evictions. Returns
null
if the cache implementation does not provide a way to track cache size.
-
hitCount
protected abstract long hitCount()- Returns:
- Get requests that resulted in a "hit" against an existing cache entry. Monotonically increasing hit count.
-
missCount
- Returns:
- Get requests that resulted in a "miss", or didn't match an existing cache
entry. Monotonically increasing count. Returns
null
if the cache implementation does not provide a way to track miss count, especially in distributed caches.
-
evictionCount
- Returns:
- Total number of entries that have been evicted from the cache.
Monotonically increasing eviction count. Returns
null
if the cache implementation does not support eviction, or does not provide a way to track the eviction count.
-
putCount
protected abstract long putCount()The put mechanism is unimportant - this count applies to entries added to the cache according to a pre-defined load function such as exists in Guava/Caffeine caches as well as manual puts. Note that Guava/Caffeine caches don't count manual puts.- Returns:
- Total number of entries added to the cache. Monotonically increasing count.
-
bindImplementationSpecificMetrics
Bind detailed metrics that are particular to the cache implementation, e.g. load duration for Caffeine caches, heap and disk size for EhCache caches. These metrics are above and beyond the basic set of metrics that is common to all caches.- Parameters:
registry
- The registry to bind metrics to.
-
getTagsWithCacheName
-