http-cache-turbo #

A full-page cache inside nginx that serves hits from shared memory, like a small Varnish without a daemon. Use it to cache whole pages of a dynamic site in front of PHP or another backend.

Source: our fork on GitHub

Read more: deep-dive article on deb.myguard.nl

Directives

cache_turbo #

syntax: cache_turbo 1 arg;  ·  context: server, location

Enables cache-turbo in this location and binds it to a shared-memory zone; accepts "off" or an optional "auto" backend-preset shorthand.

cache_turbo_admin #

syntax: cache_turbo_admin 1 arg;  ·  context: location

Turns the location into an admin/control endpoint for the named cache_turbo shared-memory zone.

cache_turbo_auto_vary #

syntax: cache_turbo_auto_vary on | off (on/off flag);  ·  context: server, location

A stale entry (being served while a refresh runs) has not been revalidated against the origin, so it serves the full body rather than asserting "still current" with a 304 (RFC 9111). ### Auto-Vary (read the response Vary) On by default (cache_turbo_auto_vary off; reverts to the old Vary-blind behavior described below).

cache_turbo_autotune #

syntax: cache_turbo_autotune on | off (on/off flag);  ·  context: server, location

What it will never do is extend the fresh TTL — a client is never told "fresh" about content older than your cache_turbo_valid contract. > Load-adaptation is folded into cache_turbo_autotune on — turning autotune > on enables all three.

cache_turbo_backend #

syntax: cache_turbo_backend 1+ args;  ·  context: server, location

Composes one or more CMS auto-classify presets (generic, wordpress, woocommerce, joomla) by setting bits in backend_presets.

cache_turbo_backend_prefix #

syntax: cache_turbo_backend_prefix 1 arg;  ·  context: server, location

Scoping the location does not help (it routes requests, it does not rewrite r->uri): declare the mount with cache_turbo_backend_prefix /forums/; (see the vhost example in docs/xenforo.md). ### Interactions and safety - Implies cache_turbo_cache_control honor (unless you set it explicitly).

cache_turbo_background_update #

syntax: cache_turbo_background_update on | off (on/off flag);  ·  context: server, location

Boolean directive — set to "on" or "off".

cache_turbo_background_update_max #

syntax: cache_turbo_background_update_max 1 arg (integer);  ·  context: server, location

P3-7: zone-wide cap on concurrent background-refresh subrequests. 0 = unlimited (default; see conf->background_update_max init and the merge below for why 0 rather than a nonzero default was chosen).

cache_turbo_beta #

syntax: cache_turbo_beta 1 arg (integer);  ·  context: server, location

Repeatable. | | cache_turbo_beta N | server, location | preset (1000) | Refresh eagerness, ×1000 (1000 = 1.0).

cache_turbo_breaker #

syntax: cache_turbo_breaker on | off (on/off flag);  ·  context: server, location

The tokens exist so the configuration vocabulary matches nginx's, and they carry their own bits so a future trigger site with access to upstream state can honour the distinction without a config break. | | cache_turbo_breaker on \| off | server, location | on | Turn the circuit breaker on for this location, independently of cache_turbo itself.

cache_turbo_breaker_count_retries #

syntax: cache_turbo_breaker_count_retries on | off (on/off flag);  ·  context: server, location

P5-5r: OPT-IN, default off -- see the field comment on breaker_count_retries in the .h for why this remains opt-in. When on, every proxy_next_upstream peer attempt that failed before the final one also counts toward the breaker's failure run.

cache_turbo_breaker_open #

syntax: cache_turbo_breaker_open 1 arg;  ·  context: server, location

A URI with no cached copy at all has nothing to fall back on, so those requests get a 503 carrying a Retry-After hint that tracks cache_turbo_breaker_open.

cache_turbo_breaker_retry_after #

syntax: cache_turbo_breaker_retry_after 1 arg (duration in seconds);  ·  context: server, location

To disable the breaker use cache_turbo_breaker off, cache_turbo_breaker_threshold 0, or cache_turbo_breaker_window 0 instead. | | cache_turbo_breaker_retry_after TIME | server, location | cache_turbo_breaker_open's effective value | Advisory Retry-After seconds sent with the breaker's 503.

cache_turbo_breaker_threshold #

syntax: cache_turbo_breaker_threshold 1 arg (integer);  ·  context: server, location

The breaker consults cache_turbo_breaker_threshold/cache_turbo_breaker_window before it can ever trip, and cache_turbo_breaker_open for how long an OPEN trip lasts before probing the origin again.

cache_turbo_breaker_window #

syntax: cache_turbo_breaker_window 1 arg (duration in seconds);  ·  context: server, location

The breaker consults cache_turbo_breaker_threshold/cache_turbo_breaker_window before it can ever trip, and cache_turbo_breaker_open for how long an OPEN trip lasts before probing the origin again.

cache_turbo_bypass #

syntax: cache_turbo_bypass 1+ args;  ·  context: server, location

Sets a predicate that, when it evaluates true, skips serving from cache and forwards the request to origin.

cache_turbo_bypass_stale_uri #

syntax: cache_turbo_bypass_stale_uri 1+ args;  ·  context: server, location

The capture path re-checks the request it stores for, so even a store that runs ahead of the bypass (cache_turbo_bypass_stale_uri) refuses an RSC response.

cache_turbo_bypass_uri #

syntax: cache_turbo_bypass_uri 1+ args;  ·  context: server, location

(cache_turbo_bypass_uri and the cache_turbo_backend presets do skip storing as well; only cache_turbo_bypass does not.) | | cache_turbo_no_store VAR... | server, location | — | If any variable is non-empty and not 0, do not store the response.

cache_turbo_cache_control #

syntax: cache_turbo_cache_control 1 arg;  ·  context: server, location

Only active under cache_turbo_cache_control honor. - no-store veto — a targeted no-store/private/max-age=0 refuses the shared store the same way a plain Cache-Control: no-store does.

cache_turbo_keep_stale #

syntax: cache_turbo_keep_stale 1 arg;  ·  context: server, location

When the origin goes down and a cached page has already expired, cache_turbo_keep_stale lets you configure that grace window instead of waiting for the app to send one: When the origin is unavailable and an entry has passed its cache_turbo_valid TTL, the response is still served (from cache) for as long as cache_turbo_keep_stale covers the request.

cache_turbo_key #

syntax: cache_turbo_key 1 arg;  ·  context: server, location

Compiles a complex-value expression used to build the cache key for matching requests.

cache_turbo_key_encoded_origin #

syntax: cache_turbo_key_encoded_origin on | off (on/off flag);  ·  context: server, location

Set cache_turbo_key_encoded_origin on to opt in: supported encoding classes are keyed separately and the serve-side guard checks that the client accepts the stored coding; HIT and stale-if-error responses restore the exact gzip, br, or zstd Content-Encoding from the validated cache stamp.

cache_turbo_l2_negative_ttl #

syntax: cache_turbo_l2_negative_ttl 1 arg;  ·  context: server, location

Changes eviction ORDER only -- never what is served, what is cacheable, or any freshness decision. | | cache_turbo_l2_negative_ttl N | server, location | 0 (off) | Remember for N seconds that an L2 (Redis/memcached) GET missed a key, so the next cold request for it skips the L2 round-trip instead of paying a full RTT to be told "absent" again.

cache_turbo_lock #

syntax: cache_turbo_lock on | off (on/off flag);  ·  context: server, location

Use it with cache_turbo_lock on, not instead of it: min_uses decides what is worth storing, single-flight decides how many requests reach the origin while a key is being filled. ## Zone sizing under LRU pressure The cache zone is a single shared-memory heap with a flat LRU (least-recently-used) eviction list.

cache_turbo_lock_timeout #

syntax: cache_turbo_lock_timeout 1 arg (duration in ms);  ·  context: server, location

Duration in milliseconds; accepts ms / s / m suffixes.

cache_turbo_lock_ttl #

syntax: cache_turbo_lock_ttl 1 arg;  ·  context: server, location

Higher = refresh sooner/more often. | | cache_turbo_lock_ttl TIME | server, location | preset (5s) | Single-flight window: once one refresh is claimed, others serve stale until it finishes.

cache_turbo_max_size #

syntax: cache_turbo_max_size 1 arg;  ·  context: server, location

Watch cache_turbo_l2_neg_skips_total against cache_turbo_l2_hits_total — rising skips with falling L2 hits means the window is too long. | | cache_turbo_max_size SIZE | server, location | 1m | Maximum serialized cached object size (metadata, stored headers, and body).

cache_turbo_memcached #

syntax: cache_turbo_memcached 1+ args;  ·  context: http, server, location

Selects the memcached L2 backend with host:port plus prefix=/timeout= params; mutually exclusive with cache_turbo_redis.

cache_turbo_min_uses #

syntax: cache_turbo_min_uses 1 arg;  ·  context: server, location

If you want the aggressive TTLs without the admission gate, set cache_turbo_min_uses 1 explicitly; an explicit directive beats the band like any other knob.

cache_turbo_min_uses_window #

syntax: cache_turbo_min_uses_window 1 arg;  ·  context: server, location

cache_turbo_no_store #

syntax: cache_turbo_no_store 1+ args;  ·  context: server, location

Sets a predicate that, when true, prevents the response from being stored in cache.

cache_turbo_normalize_max_args #

syntax: cache_turbo_normalize_max_args 1 arg (integer);  ·  context: server, location

cache_turbo_normalize_max_args caps it at 64 kept (post-strip) params by default.

cache_turbo_normalize_strip #

syntax: cache_turbo_normalize_strip 1+ args;  ·  context: server, location

Appends extra denylist parameter-name patterns to strip when normalizing the cache key's query string.

cache_turbo_normalize_vary #

syntax: cache_turbo_normalize_vary 1+ args;  ·  context: server, location

Selects which Vary buckets (encoding and/or device) are appended to the normalized cache-key arguments.

cache_turbo_preset #

syntax: cache_turbo_preset 1 arg;  ·  context: server, location

Selects a named default-tuning band (micro, conservative, balanced, aggressive) for cache knobs not explicitly overridden.

cache_turbo_probe #

syntax: cache_turbo_probe 1 arg;  ·  context: location

cache_turbo_purge #

syntax: cache_turbo_purge on | off (on/off flag);  ·  context: server, location

Unset ⇒ inert. | | cache_turbo_purge on | server, location | off | Allow a PURGE <uri> request to drop that URI's entry from L1 (+L2).

cache_turbo_redis #

syntax: cache_turbo_redis 1+ args;  ·  context: http, server, location

Configures the Redis L2 backend from a redis(s):// DSN or host:port, with optional auth/db/TLS/prefix/timeout params.

cache_turbo_require_header #

syntax: cache_turbo_require_header 1 arg;  ·  context: server, location

A malformed valued max-stale grants no stale tolerance. ### Letting the origin decide (cache_turbo_require_header) Everything above is the module deciding from the HTTP it can see.

cache_turbo_scan_resistant #

syntax: cache_turbo_scan_resistant 1 arg;  ·  context: server, location

It is 184 whether or not cache_turbo_scan_resistant is enabled -- the fields exist unconditionally, they are simply never set to a non-zero value when the feature is off.

cache_turbo_serve_authorized #

syntax: cache_turbo_serve_authorized on | off (on/off flag);  ·  context: server, location

Boolean directive — set to "on" or "off".

cache_turbo_stale_mult #

syntax: cache_turbo_stale_mult 1 arg;  ·  context: server, location

0 is rejected at config time (use cache_turbo_lock off to disable single-flight instead); an oversized value is clamped rather than rejected. | | cache_turbo_stale_mult N | server, location | preset (4 balanced) | Stale window as a multiple of the fresh TTL: an entry stays serveable as STALE until cache_turbo_valid * N.

cache_turbo_store_head #

syntax: cache_turbo_store_head on | off (on/off flag);  ·  context: server, location

cache_turbo_store_head on; makes a HEAD miss fire one internal background subrequest — a real GET — so the URL gets an entry: The subrequest goes through the ordinary capture gate and the ordinary store path; this feature adds no second way for an entry to be created.

cache_turbo_suppress_native #

syntax: cache_turbo_suppress_native on | off (on/off flag);  ·  context: server, location

It affects cache identity only when selected by an explicit cache_turbo_key; the built-in key uses the raw request URI. | | $cache_turbo_active | 1 when cache-turbo is engaged for this request (enabled, cacheable method, main request) and cache_turbo_suppress_native on; else 0.

cache_turbo_surrogate_key #

syntax: cache_turbo_surrogate_key on | off (on/off flag);  ·  context: server, location

cache_turbo_surrogate_key on mirrors the same cache_turbo_tag list back downstream as a Surrogate-Key header, so the fronting CDN keys the edge copy on the identical tags and the two stay purge-synced: Semantics: - MISS and HIT. The header rides every response for the representation, not only the one that populated the cache.

cache_turbo_tag #

syntax: cache_turbo_tag 1 arg;  ·  context: server, location

Compiles a complex-value expression producing whitespace/comma-separated cache tags recorded against the stored object for later purge.

cache_turbo_test_force_file_buf #

syntax: cache_turbo_test_force_file_buf on | off (on/off flag);  ·  context: server, location

Boolean directive — set to "on" or "off".

cache_turbo_test_l2_promote_hold_ms #

syntax: cache_turbo_test_l2_promote_hold_ms 1 arg (integer);  ·  context: server, location

AUD-L2-PROMOTE-RACE: the gap between the resumed L2-hit handler's own (already-unlocked) L1 re-check and its store_if() call is pure CPU with no I/O or yield point in between -- unreachable from a black-box HTTP timing race. This blocks the CURRENT WORKER for up to N ms, right before the promote call, so a test can land a concurrent write from a DIFFERENT worker into that exact window. ngx_msleep is a plain usleep(): it stalls only this worker's event loop, not the others, so with >1 worker configured the concurrent write is unaffected. 0/unset = no hold (production default; the directive does not exist outside TEST_FAULTS builds at all).

cache_turbo_test_midbody_abort #

syntax: cache_turbo_test_midbody_abort on | off (on/off flag);  ·  context: server, location

What exists is a deterministic test-only fault path, gated behind the build-time TEST_FAULTS flag and the cache_turbo_test_midbody_abort directive (used by this module's own test suite to force a mid-body failure predictably); it is not compiled into a normal build and there is no way to turn it on in production.

cache_turbo_test_restore_alloc_fail #

syntax: cache_turbo_test_restore_alloc_fail on | off (on/off flag);  ·  context: server, location

Boolean directive — set to "on" or "off".

cache_turbo_test_scan_del_fail #

syntax: cache_turbo_test_scan_del_fail on | off (on/off flag);  ·  context: server, location

GRIND-C6-READSCAN: force the ?all=1 SCAN-del walk's per-page del_many() to report NGX_ERROR, so the "UNLINK never launched" abandon-and-report- INCOMPLETE branch is reachable without a real OOM/backoff.

cache_turbo_test_scan_max_pages #

syntax: cache_turbo_test_scan_max_pages 1 arg (integer);  ·  context: server, location

AUD-SCAN1: lower the SCAN-del page cap so the "abandon the walk and report INCOMPLETE" branch is reachable without a 268M-key keyspace.

cache_turbo_test_scan_page_hold_ms #

syntax: cache_turbo_test_scan_page_hold_ms 1 arg (integer);  ·  context: server, location

S231-L2-SCANTIME: hold the worker at every SCAN page boundary so the walk's wall-clock deadline check is reachable without depending on how fast the runner is. The completion check returns before the deadline check, so a walk that finishes never evaluates the deadline; this makes a non-final page boundary outlive any deadline under test. Blocking ngx_msleep for the same reason as the promote hold below. 0/unset = no hold.

cache_turbo_test_store_fail #

syntax: cache_turbo_test_store_fail on | off (on/off flag);  ·  context: server, location

Boolean directive — set to "on" or "off".

cache_turbo_test_varidx_fail #

syntax: cache_turbo_test_varidx_fail on | off (on/off flag);  ·  context: server, location

COR-5(b): arm the per-request variant-index drop. See the test_varidx_fail field comment for why the trigger is a request header and not "take Redis down".

cache_turbo_test_warm_ctx_fail #

syntax: cache_turbo_test_warm_ctx_fail on | off (on/off flag);  ·  context: server, location

P3-7: force warm_one()'s post-rebuild setup to fail (posted subrequest, ctx already seeded, early NGX_ERROR return) so the bg_inflight leak scenario is testable on demand.

cache_turbo_use_stale #

syntax: cache_turbo_use_stale 1+ args;  ·  context: server, location

cache_turbo_use_stale picks the trigger set: Tokens: off, error, timeout, http_403, http_404, http_429, http_500, http_502, http_503, http_504.

cache_turbo_valid #

syntax: cache_turbo_valid 1+ args;  ·  context: server, location

Sets the fresh-cache TTL, either as the default/200 TTL or per listed HTTP status code(s).

cache_turbo_vary_ignore #

syntax: cache_turbo_vary_ignore 1+ args;  ·  context: server, location

Default auto-Vary refuses axes it does not know, so without this preset no App Router page is ever stored; with cache_turbo_vary_ignore on those names and no bypass, one RSC: 1 request poisons the HTML entry for every visitor (GHSA-wfc6-r584-vfw7).

cache_turbo_vary_marker_revalidate #

syntax: cache_turbo_vary_marker_revalidate 1 arg;  ·  context: server, location

cache_turbo_warm_max #

syntax: cache_turbo_warm_max 1 arg;  ·  context: server, location

Gate with allow/deny. | | cache_turbo_warm_max N | server, location | 32 | Ceiling on how many URLs one POST /_cache?url=... or ?url_file=... request may fire warm subrequests for — bounds the operator-supplied origin fan-out a single admin call can trigger.

Example

load_module modules/ngx_http_cache_turbo_module.so;

http {
    # ── http context only ───────────────────────────────────────────────
    cache_turbo_zone name=ct 256m;          # declare the shm zone (min 8 pages)

    # L2 tier — pick AT MOST ONE of the next two (mutually exclusive per block).
    # Both also valid at server/location scope; declared here they're inherited.
    cache_turbo_redis     redis://127.0.0.1:6379/0 prefix=ct: timeout=250ms
                          tls=off tls_verify=on keepalive=0 keepalive_timeout=60s;
  # cache_turbo_memcached 127.0.0.1:11211 prefix=ct: timeout=250ms
  #                       keepalive=0 keepalive_timeout=60s;

    server {
        listen 80;
        server_name example.com;

        location / {
            # ── turn it on ──────────────────────────────────────────────
            cache_turbo                   ct;        # bind zone "ct" (or: off)
            cache_turbo_backend           wordpress; # presets stack with '|' or spaces; see the directive table/docs for the full list; 'none' = off; implies cache_control honor

            # ── what is "the same page" ─────────────────────────────────
            cache_turbo_key               $host$uri$cache_turbo_normalized_args;  # explicit normalized opt-in
            cache_turbo_key_encoded_origin off;  # require explicit encoded-origin opt-in
            cache_turbo_normalize_strip   sid sessionid "tmp_*";   # extra args to drop (trailing * = prefix; bare * = all)
            cache_turbo_normalize_max_args 64;        # cap sorted query args
            cache_turbo_normalize_vary    encoding device;        # add variant buckets to the key

            # ── freshness / staleness ───────────────────────────────────
            cache_turbo_preset            balanced;  # micro|conservative|balanced|aggressive — sets the 5 knobs below
            cache_turbo_stale_mult         4;         # stale window multiplier (balanced)
            cache_turbo_valid             60s;       # 200 TTL; 0 = cache forever
            cache_turbo_valid             301 302 308 1h;   # repeatable: cache redirects
            cache_turbo_valid             404 410 1m;       #            negative caching
            cache_turbo_beta              1000;      # refresh eagerness ×1000
            cache_turbo_lock_ttl          5s;        # single-flight refresh window
            cache_turbo
…

↑ back to index