CLI man page:
safesquid-prefetch(5)Prefetch queue flow
Overview
ThePrefetch section (safesquid-prefetch(5)) configures SafeSquid to proactively download resources into its cache before the client actually requests them.
Core Mechanics (C++ Source Validation)
Async queue, cache pre-check, HTML parser first-match.- Asynchronous Queue: Prefetching is driven by an asynchronous, background worker thread (
prefetch_thread) that monitors aPREFETCH_QUEUE. It does not block the primary client connection. - Cache Pre-Validation: Before initiating a prefetch download, the thread checks if the object exists in the cache. If the object is already cached, the prefetch is aborted to save bandwidth.
- Request Spoofing: The background thread creates a synthetic, unattached HTTP connection, forces it through the routing pipeline, and uses a hardcoded User-Agent to request the file from the origin.
Schema Fields
Global Fields
- Enabled (enabled): When off, setup_callbacks does not register HTML parsers — no automatic prefetch.
- Threads (threads): Configured worker count for prefetch queue processing. This value is not applied in the current build.
- Queue size (queuesize): Maximum URLs waiting in the prefetch queue; full queue rejects new URLs. Already-cached URLs are not queued.
- Host limit (hostlimit): Maximum queued prefetches per host name ( 0 disables per-host cap). Duplicate URLs are never queued twice.
Rule-Based Fields (Per Connection Tuning)
- Enabled (enabled): Disabled rows are skipped. Enabled rows are tested top to bottom; the first HTML-parser match queues prefetch URLs.
- Comment (comment): Operator notes only. Does not affect prefetch matching.
- Profiles (profiles): Limit this entry to connections that already carry these Access Profile tags. SafeSquid tests against the connection’s active profiles: blank ignores profiles; a positive tag applies when present; prefix ! applies when absent. With multiple tags, the first list entry that resolves decides (positive match -> apply; negated match -> skip; lone unmatched ! -> apply). Prefetch HTML parser rules are walked top to bottom; the first matching row decides which tag/attribute URLs are queued for early fetch.
- Tag name (tag): HTML element name to scan in text/html responses (case-insensitive). Example: a , img , link . Blank skips this row during parser matching.
- Tag attribute (attribute): Attribute on the tag that holds the URL (for example href or src ). When present on the element, its value is passed to the URL regex below.
- Attribute pattern (pattern): POSIX regex tested against the attribute URL after tag/attribute match. On match, the URL is resolved and queued (unless already cached or queue full). Blank accepts any non-empty attribute value.
- Maximum file size (maxsize): Skip prefetch when the response Content-Length exceeds this size. 0 = no size cap.
- Recursion level (recursion): Set the Recursion limit to 0, or a higher positive integer. Prefetched content is analyzed, to discover new prefetchable URLs. Recursion limits this iteration. Note: Setting to 0 causes links to be followed, indefinitely.
- appcontent (appcontent): No description provided.
Prefetch rule fields
- Profiles — Limit the rule to connections with matching Access Profile tags. Blank matches all.
- Tag name — HTML element to scan (case-insensitive), for example
a,img,link. Blank skips the row. - Tag attribute — Attribute holding the URL (for example
hreforsrc). - Attribute pattern — POSIX regex on the attribute value after tag/attribute match. Blank accepts any non-empty value. On match, the URL is resolved and queued unless cached or queue full.
- Maximum file size — Skip prefetch when response Content-Length exceeds this size.
0= no cap. - Recursion level — How many levels prefetched HTML is analyzed for further links. Note: setting
0follows links indefinitely per field help.
Processing order
- Enable Prefetching and Caching.
- During HTML responses, enabled Prefetch rows are checked top to bottom.
- The first row whose profiles match and whose tag/attribute/pattern succeeds drives prefetch for that parser pass.
- Matched URLs enter the queue subject to queue size, host limit, and cache state.
- Caching Prefetch window limits duplicate prefetch writes for the same URL within N seconds.
Some prefetch hooks and the Prefetch now CGI handler require
ENABLE_PREFETCH at build time. If manual prefetch fails, confirm your build includes prefetch support.Examples
How to verify
- Enable CACHE in
LOG_LEVEL; look for cache writes with prefetch-related flags. - Load an HTML page twice — second load should show cache hits for prefetched assets when Caching and rules allow.
- Use Manage cached objects to search for prefetched URLs.
- Watch queue rejection if Queue size or Host limit is exceeded (reduce rules or raise limits).

