-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Statistics
Ben Manes edited this page Sep 16, 2024
·
8 revisions
Cache<Key, Graph> graphs = Caffeine.newBuilder()
.maximumSize(10_000)
.recordStats()
.build();By using Caffeine.recordStats(), you can turn on statistics collection. The Cache.stats() method returns a CacheStats which provides statistics such as
-
hitRate():returns the ratio of hits to requests -
evictionCount():the number of cache evictions -
averageLoadPenalty():the average time spent loading new values
These statistics are critical in cache tuning and we advise keeping an eye on these statistics in performance-critical applications.
The cache statistics can be integrated with a reporting system using either a pull or push based approach. A pull-based approach periodically calls Cache.stats() and records the latest snapshot. A push-based approach supplies a custom StatsCounter so that the metrics are updated directly during the cache operations.
See metrics-caffeine if using Dropwizard Metrics.
Try prometheus-java if using Prometheus.
Can't choose? Try the Micrometer integration.

