Class CacheWarmer

java.lang.Object
org.frontcache.warmer.CacheWarmer

public class CacheWarmer extends Object
Runs one URI list through this node's own front door, paced, and reports what happened.

How an entry is warmed

By an ordinary GET to this node's own connector (LoopbackWarmTransport), with the key base's Host and the warm token (WarmRequest). The request then takes exactly the path a visitor's does - the cache processor, the include loop, filter-mode transport, the resilience wrappers - so this class has no opinion about cacheability, keys or includes. An in-process fetch-and-store would be a second copy of the cache-fill logic, and this project already knows what two copies of that logic do: the eviction block duplicated in CacheProcessorBase and IncludeProcessorBase, where fixing one only is how it regresses.

The run

IDLE -> RUNNING <-> PAUSED -> STOPPING -> IDLE
At most one run per node. Workers are virtual threads that pull the next line from one shared reader, so only the reader holds file state and memory does not depend on the list's size. Each worker sleeps delayMs after each request; delayMs and concurrency can be changed while the run is going - a new delay applies to sleeps already in progress, and a lower concurrency retires the surplus workers as they finish their current request. Before each request a worker checks the Cache-Miss breaker - the origin's - and waits while it is open, without counting the wait against the list. After front-cache.warmer.auto-pause-after-failures consecutive failures the run pauses itself. The position is checkpointed every CHECKPOINT_EVERY entries and on pause or stop; a restart offers to resume from it but never does so by itself. See docs/cache-warmer-proposal.md.
  • Field Details

  • Method Details

    • getInstance

      public static CacheWarmer getInstance()
      The node's warmer, created on first use.
    • existingInstance

      public static CacheWarmer existingInstance()
      The warmer if one has been created, without creating one - for the metrics exporter.
    • entriesTotal

      public static long entriesTotal(String result)
      Returns:
      how many entries have ended with result on this node, across runs
    • isRunning

      public boolean isRunning()
    • getStore

      public WarmerListStore getStore()
    • config

      public WarmerConfig config()
      The node's current front-cache.warmer.* settings.
    • preflight

      public WarmerPreflight preflight(WarmerRunParams requested, String loopbackTarget, String loopbackProblem, CacheProcessor processor)
      What a run with these parameters would do - see WarmerPreflight. Reads the list once and samples the cache; never calls the origin.
      Parameters:
      processor - the cache to sample, or null to skip the cache samples
    • defaultKeyBase

      public static String defaultKeyBase(WarmerConfig config, boolean requestSecure)
      The default key base: front-cache.warmer.key-base, else <scheme>://<default-domain>, else null - in which case a run cannot start until the operator names one. The scheme is the management request's isSecure(). That is the wrong signal for the loopback connector (see WarmerActions.loopbackTarget) and the right one for the key: the console normally reaches a node through the same front door as visitors, and the container resolves a forwarded scheme for both alike - https on the bundled Jetty behind a TLS-terminating nginx, http on a container that ignores X-Forwarded-Proto. It is only a default; the preflight's sample keys and cache sample are the check.
      Parameters:
      requestSecure - the management request's isSecure(), false when there is none
    • start

      public WarmerStatus start(WarmerRunParams requested, String loopbackTarget) throws CacheWarmer.RefusedException
      Starts a run. Returns once the workers are started - the run belongs to the node from here, and closing the console does not stop it.
      Parameters:
      loopbackTarget - where warm requests go - see WarmerActions.loopbackTarget
      Throws:
      CacheWarmer.RefusedException
    • update

      public WarmerStatus update(Long delayMs, Integer concurrency) throws CacheWarmer.RefusedException
      Changes the delay and/or the concurrency of the running run. A null leaves that one as it is.
      Throws:
      CacheWarmer.RefusedException
    • pause

    • resume

    • stop

      Lets in-flight requests finish, closes the failed list, and writes the checkpoint.
      Throws:
      CacheWarmer.RefusedException
    • status

      public WarmerStatus status()