-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Statistics
Ben Manes edited this page Sep 12, 2016
·
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 difference since the last 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.

