Statistics (original) (raw)

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

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.