Class CacheStats

java.lang.Object
com.palantir.tritium.metrics.caffeine.CacheStats
All Implemented Interfaces:
com.github.benmanes.caffeine.cache.stats.StatsCounter, Supplier<com.github.benmanes.caffeine.cache.stats.StatsCounter>

public final class CacheStats extends Object implements com.github.benmanes.caffeine.cache.stats.StatsCounter, Supplier<com.github.benmanes.caffeine.cache.stats.StatsCounter>
  • Method Summary

    Modifier and Type
    Method
    Description
    com.github.benmanes.caffeine.cache.stats.StatsCounter
    get()
     
    static CacheStats
    of(com.palantir.tritium.metrics.registry.TaggedMetricRegistry taggedMetricRegistry, @Safe String name)
    Creates a CacheStats instance that can be used to record metrics for Caffeine cache statistics.
    void
    recordEviction(int weight, com.github.benmanes.caffeine.cache.RemovalCause cause)
     
    void
    recordHits(int count)
     
    void
    recordLoadFailure(long loadTime)
     
    void
    recordLoadSuccess(long loadTime)
     
    void
    recordMisses(int count)
     
    <K,V> void
    register(com.github.benmanes.caffeine.cache.Cache<K,V> cache)
    Registers additional metrics for a Caffeine cache.
    <K, V, C extends com.github.benmanes.caffeine.cache.Cache<K,V>>
    C
    register(Function<CacheStats, C> cacheFactory)
    Constructs and registers metrics for Caffeine cache statistics.
    <K, V, C extends com.github.benmanes.caffeine.cache.AsyncCache<K,V>>
    C
    registerAsync(Function<CacheStats, C> cacheFactory)
    Constructs and registers metrics for Caffeine cache statistics.
    com.github.benmanes.caffeine.cache.stats.CacheStats
     
     

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Method Details

    • of

      public static CacheStats of(com.palantir.tritium.metrics.registry.TaggedMetricRegistry taggedMetricRegistry, @Safe @Safe String name)
      Creates a CacheStats instance that can be used to record metrics for Caffeine cache statistics.

      Example usage:

          Cache<Integer, String> cache = CacheStats.of(taggedMetricRegistry, "your-cache-name")
                  .register(stats -> Caffeine.newBuilder()
                          .recordStats(stats)
                          .build());
      
      Parameters:
      taggedMetricRegistry - tagged metric registry to add cache metrics
      name - cache name
      Returns:
      Caffeine stats instance to register via Caffeine.recordStats(Supplier).
    • register

      public <K,V> void register(com.github.benmanes.caffeine.cache.Cache<K,V> cache)
      Registers additional metrics for a Caffeine cache.
      Parameters:
      cache - cache for which to register metrics
    • register

      public <K, V, C extends com.github.benmanes.caffeine.cache.Cache<K,V>> C register(Function<CacheStats, C> cacheFactory)
      Constructs and registers metrics for Caffeine cache statistics.

      In order to record metrics, the cacheFactory must use the provided CacheStats with Caffeine.recordStats(Supplier))}.

      Example usage:

          Cache<Integer, String> cache = CacheStats.of(taggedMetricRegistry, "your-cache-name")
                  .register(stats -> Caffeine.newBuilder()
                          .recordStats(stats)
                          .build());
      
      Parameters:
      cacheFactory - method which will be invoked to construct the cache
      Returns:
      the constructed cache instance
    • registerAsync

      public <K, V, C extends com.github.benmanes.caffeine.cache.AsyncCache<K,V>> C registerAsync(Function<CacheStats, C> cacheFactory)
      Constructs and registers metrics for Caffeine cache statistics.

      In order to record metrics, the cacheFactory must use the provided CacheStats with Caffeine.recordStats(Supplier))}.

      Example usage:

          AsyncCache<Integer, String> cache = CacheStats.of(taggedMetricRegistry, "your-cache-name")
                  .register(stats -> Caffeine.newBuilder()
                          .recordStats(stats)
                          .buildAsync());
      
      Parameters:
      cacheFactory - method which will be invoked to construct the cache
      Returns:
      the constructed cache instance
    • get

      public com.github.benmanes.caffeine.cache.stats.StatsCounter get()
      Specified by:
      get in interface Supplier<com.github.benmanes.caffeine.cache.stats.StatsCounter>
    • recordHits

      public void recordHits(int count)
      Specified by:
      recordHits in interface com.github.benmanes.caffeine.cache.stats.StatsCounter
    • recordMisses

      public void recordMisses(int count)
      Specified by:
      recordMisses in interface com.github.benmanes.caffeine.cache.stats.StatsCounter
    • recordLoadSuccess

      public void recordLoadSuccess(long loadTime)
      Specified by:
      recordLoadSuccess in interface com.github.benmanes.caffeine.cache.stats.StatsCounter
    • recordLoadFailure

      public void recordLoadFailure(long loadTime)
      Specified by:
      recordLoadFailure in interface com.github.benmanes.caffeine.cache.stats.StatsCounter
    • recordEviction

      public void recordEviction(int weight, com.github.benmanes.caffeine.cache.RemovalCause cause)
      Specified by:
      recordEviction in interface com.github.benmanes.caffeine.cache.stats.StatsCounter
    • snapshot

      public com.github.benmanes.caffeine.cache.stats.CacheStats snapshot()
      Specified by:
      snapshot in interface com.github.benmanes.caffeine.cache.stats.StatsCounter
    • toString

      public String toString()
      Overrides:
      toString in class Object