Skip to content

Metrics

Alex Peck edited this page Nov 25, 2023 · 7 revisions

Metrics are disabled by default for ConcurrentLru. By calling the builder method WithMetrics you can turn on metrics.

ICache<int, int> lru = new ConcurrentLruBuilder<int, int>()
   .WithMetrics()
   .Build();

For ConcurrentLfu metrics are always enabled since the buffered reads and writes mitigate any performance penalty.

To retrieve metrics from the cache, use the Metrics property.

long hits = lru.Metrics.Value.Hits;

Available metrics

  • Hit count
  • Miss count
  • Hit ratio
  • Eviction count
  • Update count

Under the hood

Internally metrics are implemented using the BitFaster.Caching.Counters.Counter class, a .NET implementation of Java's LongAdder. This is a scalable counter class that supports very high concurrent throughput.