Skip to content

Statistics

Ben Manes edited this page Aug 10, 2017 · 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 stats-metrics for a simple example using Dropwizard Metrics.

Try simpleclient-caffeine if using Prometheus.

Can't choose? Try the Micrometer integration.

Clone this wiki locally