Class FcCacheMetrics

java.lang.Object
org.frontcache.cache.FcCacheMetrics

public class FcCacheMetrics extends Object
Cache read outcomes, counted per tier.

Why these are counted here and not derived

Hit ratio is the number an operator alerts on, and nothing in the process could produce it before this class. The dashboard's Cache-Hit command counts cache lookups - every one of them, hit or miss - because it measures the call, not the answer. The request log has the per-request verdict but is a log, not a metric. So the counters are taken where the answer is actually known: inside each getFromCacheImpl, which is the single read path every cache processor goes through (CacheProcessorBase.getFromCache → FC_ThroughCache → the impl).

Why the tier is part of it

"Hit ratio 90%" and "hit ratio 90%, nine tenths of it off disk" call for different actions - the second says L1 is undersized. Splitting hits by tier is what makes the number actionable, and it is cheap: the tier is already known at the point the hit happens.

Monotonic, never rolling

Unlike FcCommandMetrics, which keeps a rolling window because the SSE dashboard needs a 10-second view, these only ever go up. Their consumer is Prometheus, which computes its own windows with rate() - and a counter that decreases reads as a process restart there. Nothing needs the rolling form, so it is not built.
  • Method Details

    • record

      public static void record(FcCacheMetrics.Outcome outcome)
      Records one cache read. Called on the request path, so it is a LongAdder increment and nothing else - no allocation, no lock, no branch on whether export is even enabled. Counting unconditionally keeps the numbers correct for a node that has export turned on later, and costs less than the check would.
    • recordHitOrMiss

      public static void recordHitOrMiss(Object cachedResponse, FcCacheMetrics.Outcome hitOutcome)
      Convenience for the common two-branch case: a resolved response, or null for a miss.
    • count

      public static long count(FcCacheMetrics.Outcome outcome)
      Returns:
      reads with this outcome since JVM start
    • reset

      public static void reset()
      Test seam - back to zero.