> ## Documentation Index
> Fetch the complete documentation index at: https://docs.safesquid.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Accelerators

**Accelerators** groups the two sections that speed up repeat access: **Caching** stores responses in memory for reuse, and **Prefetch** proactively downloads resources before a client requests them. They interact — a prefetched object is only useful if Caching later serves it — so both live on this one page.

<Tabs>
  <Tab title="Caching">
    The **Cache** section controls in-memory HTTP caching, refresh policy, and ICP parameters for forwarding.

    <Frame caption="Cache read path">
      <img src="https://mintcdn.com/safe-squid-labs-12a0916f/VRx-_vpMam8ezhZz/images/admin_guide/caching_flowchart.svg?fit=max&auto=format&n=VRx-_vpMam8ezhZz&q=85&s=71a71b8579f8bbe136f7c241e23d5feb" alt="Cache open flow" width="480" height="320" data-path="images/admin_guide/caching_flowchart.svg" />
    </Frame>

    ## Core mechanics

    ### Refresh — first match wins

    Walk Refresh rows top-down; first enabled row whose profiles match sets min/max age, validate, and cachable flag, then stops. `cachable=FALSE` sets `CACHE_INVALID` unless `CACHE_FORCE`.

    <Warning>
      **Disk store is hard-disabled.** Disk store selection is inactive — new objects are memory-only regardless of Store row configuration.
    </Warning>

    ### Violate RFC

    Objects stored despite `no-cache` / `no-store` get `CACHE_VIOLATION`. When **Violate RFC** is off, reads return NULL (not served). When on, violation objects may be served.

    ## Examples

    Open **Configure → Application Setup → Accelerators → Caching → Refresh**. Row fields are
    Enabled, Comment, Profiles, Cachable, Minimum/Maximum age, Revalidate age, and Last-Modified
    time factor.

    <Frame caption="Caching — Refresh rows">
      <img src="https://mintcdn.com/safe-squid-labs-12a0916f/xUbSVUmS93A4aMLc/images/admin_guide/accelerators-caching_refresh.webp?fit=max&auto=format&n=xUbSVUmS93A4aMLc&q=85&s=f5c03fde4e4758cc3752acbaea5d21ac" alt="SafeSquid console showing Caching Refresh rows including a Do not cache entry, the Edit Policies icon on the first row circled" width="1440" height="700" data-path="images/admin_guide/accelerators-caching_refresh.webp" />
    </Frame>

    <Tip>
      ### Uncachable profile on top

      **Config:** Refresh row 1 profiles `uncachable`, cachable off; row 2 blank profiles, cachable on.

      **Result:** Tagged connections get CACHE\_INVALID on new entries; others use row 2 ages.
    </Tip>

    <Tip>
      ### Violate RFC off

      **Config:** violaterfc false; stored no-store object.

      **Result:** Second client does not receive object from cache — miss to origin.
    </Tip>

    <Tip>
      ### Store row present

      **Config:** Store enabled with path and quota.

      **Result:** select\_store still NULL — memory-only in current builds.
    </Tip>

    ## How to verify

    1. Enable CACHE in `LOG_LEVEL`.
    2. Repeat URL request; check Detailed logs for hit/miss.
    3. Use Manage cached objects to inspect or purge entries.
  </Tab>

  <Tab title="Prefetch">
    The **Prefetch** section configures SafeSquid to proactively download resources into its cache before the client actually requests them.

    <Frame caption="Prefetch queue flow">
      <img src="https://mintcdn.com/safe-squid-labs-12a0916f/VRx-_vpMam8ezhZz/images/admin_guide/prefetching_flowchart.svg?fit=max&auto=format&n=VRx-_vpMam8ezhZz&q=85&s=d18c72039bbdd786f7fd469c6bf3be87" alt="Prefetch queue flow" width="480" height="160" data-path="images/admin_guide/prefetching_flowchart.svg" />
    </Frame>

    ## Core mechanics

    Async queue, cache pre-check, HTML parser first-match.

    * **Asynchronous Queue**: Prefetching is driven by an asynchronous, background worker thread (`prefetch_thread`) that monitors a `PREFETCH_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.

    ### 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.

    ### 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 `href` or `src`).
    * **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 `0` follows links indefinitely per field help.

    ### Processing order

    1. Enable Prefetching and Caching.
    2. During HTML responses, enabled Prefetch rows are checked top to bottom.
    3. The first row whose profiles match and whose tag/attribute/pattern succeeds drives prefetch for that parser pass.
    4. Matched URLs enter the queue subject to queue size, host limit, and cache state.
    5. Caching **Prefetch window** limits duplicate prefetch writes for the same URL within N seconds.

    <Note>
      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.
    </Note>

    ## Examples

    The **Prefetch** rule-row list ships empty by default — no live example available for a rule
    row. **Prefetch now** is populated and matches Example 3 below.

    Open **Configure → Application Setup → Accelerators → Prefetch → Prefetch now**.

    <Frame caption="Prefetch — Prefetch now">
      <img src="https://mintcdn.com/safe-squid-labs-12a0916f/xUbSVUmS93A4aMLc/images/admin_guide/accelerators-prefetch_now.webp?fit=max&auto=format&n=xUbSVUmS93A4aMLc&q=85&s=a9278d3428a082d62d2b692d5485a7f0" alt="SafeSquid console showing the Prefetch now URL field for manually queuing a page" width="1440" height="450" data-path="images/admin_guide/accelerators-prefetch_now.webp" />
    </Frame>

    <Tip>
      ### 1 — Prefetch linked CSS and scripts

      * Row 1: Tag `link`, attribute `href`, pattern `\.css$`
      * Row 2: Tag `script`, attribute `src`, pattern blank

      **Result:** on HTML pages, stylesheets matching `.css` and all script `src` URLs are queued for early fetch when row 1 or 2 matches first for that element scan order.
    </Tip>

    <Tip>
      ### 2 — Staff-only prefetch

      * Prefetch row Profiles: `STAFF`
      * Access Profiles adds `STAFF` for internal users only

      **Result:** only staff connections trigger automatic prefetch; other users parse HTML without prefetch queue activity from that row.
    </Tip>

    <Tip>
      ### 3 — Manual warm-up of a portal page

      * **Prefetch now**: enter `https://intranet.example.com/`

      **Result:** when the handler is enabled, the URL is queued and fetched into cache so the next user request may hit cache immediately.
    </Tip>

    ## How to verify

    1. Enable CACHE in `LOG_LEVEL`; look for cache writes with prefetch-related flags.
    2. Load an HTML page twice — second load should show cache hits for prefetched assets when Caching and rules allow.
    3. Use the Caching tab above to search for prefetched URLs among Manage cached objects.
    4. Watch queue rejection if Queue size or Host limit is exceeded (reduce rules or raise limits).
  </Tab>
</Tabs>


## Related topics

- [Performance Accelerators](/use_cases/performance_acceleration/performance_accelerators.md)
- [Caching and Prefetching](/use_cases/performance_acceleration/caching.md)
- [Architecture and request pipeline](/admin_guide/start_here/architecture.md)
