Class CacheWarmer
java.lang.Object
org.frontcache.warmer.CacheWarmer
Runs one URI list through this node's own front door, paced, and reports what happened.
How an entry is warmed
By an ordinaryGET 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 -> IDLEAt 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.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classA start, update or control call that was refused, with a reason fit for an operator.static enum -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionconfig()The node's currentfront-cache.warmer.*settings.static StringdefaultKeyBase(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.static longentriesTotal(String result) static CacheWarmerThe warmer if one has been created, without creating one - for the metrics exporter.static CacheWarmerThe node's warmer, created on first use.getStore()booleanpause()preflight(WarmerRunParams requested, String loopbackTarget, String loopbackProblem, CacheProcessor processor) What a run with these parameters would do - seeWarmerPreflight.resume()start(WarmerRunParams requested, String loopbackTarget) Starts a run.status()stop()Lets in-flight requests finish, closes the failed list, and writes the checkpoint.Changes the delay and/or the concurrency of the running run.
-
Field Details
-
RESULT_STORED
- See Also:
-
RESULT_FRESH
- See Also:
-
RESULT_NOT_CACHEABLE
- See Also:
-
RESULT_FAILED
- See Also:
-
RESULT_INVALID
- See Also:
-
RESULTS
The label values offrontcache_warmer_entries_total, in a stable order.
-
-
Method Details
-
getInstance
The node's warmer, created on first use. -
existingInstance
The warmer if one has been created, without creating one - for the metrics exporter. -
entriesTotal
- Returns:
- how many entries have ended with
resulton this node, across runs
-
isRunning
public boolean isRunning() -
getStore
-
config
The node's currentfront-cache.warmer.*settings. -
preflight
public WarmerPreflight preflight(WarmerRunParams requested, String loopbackTarget, String loopbackProblem, CacheProcessor processor) What a run with these parameters would do - seeWarmerPreflight. 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
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'sisSecure(). That is the wrong signal for the loopback connector (seeWarmerActions.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 ignoresX-Forwarded-Proto. It is only a default; the preflight's sample keys and cache sample are the check.- Parameters:
requestSecure- the management request'sisSecure(), 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 - seeWarmerActions.loopbackTarget- Throws:
CacheWarmer.RefusedException
-
update
Changes the delay and/or the concurrency of the running run. A null leaves that one as it is.- Throws:
CacheWarmer.RefusedException
-
pause
- Throws:
CacheWarmer.RefusedException
-
resume
- Throws:
CacheWarmer.RefusedException
-
stop
Lets in-flight requests finish, closes the failed list, and writes the checkpoint.- Throws:
CacheWarmer.RefusedException
-
status
-