Cache Turbo#
The cache_turbo module caches backend responses inside Angie: the
first request for a page goes to the backend, and the following ones get the
stored copy without reaching it. Unlike proxy_cache, which keeps cached
responses in files on disk, the module keeps them in a shared memory zone that
all worker processes use.
A cached copy stays fresh for a set time and then becomes stale. Angie keeps
serving the stale copy while one of the requests refreshes it from the backend
in the background (stale-while-revalidate), so clients do not wait for the
backend. If the backend is unavailable or responds with a 5xx error, Angie
serves the copy it already has, marked X-Cache: STALE-IF-ERROR
(stale-if-error).
The cache key can drop tracking parameters such as To install the module, use one of the following packages: Angie: Angie PRO: The main directives of the module: The module also provides variables: All directives with their defaults are described in the
module documentation. To use the module, load it in the Here, Angie caches the backend responses in the The The first request for a page goes to the backend, and Angie stores the
response; it has no The same page without the tracking parameter has the same key, so Angie
returns the stored copy. The Once ten seconds have passed, the copy is stale, but Angie still returns it
at once, marked To purge the copy, pass its key to the admin endpoint; here, the key is the
host name and the path. The next request goes to the backend again and gets a
new page: The Purging by tag works only with this tier: After two news pages and one other page get cached, a purge by the
The Version: v1.1.0 Detailed documentation and source code are available at:
myguard-labs/nginx-cache-turbo-moduleutm_* and ignore
the order of query arguments, so equivalent URLs share one copy. An admin
endpoint reports cache statistics and purges cached copies by key or all at
once. With an optional Redis tier, several Angie servers share one cache, and
copies can also be purged by tag.Installation#
angie-module-cache-turboangie-pro-module-cache-turboDirectives#
cache_turbo_zone — sets the name and size of the shared memory zone
that holds the cached copies; allowed only in the http contextcache_turbo — enables caching in a server or
location and selects the zone; off disables caching, for
example for pages with personal contentcache_turbo_valid — sets how long a cached copy stays fresh; status
codes listed before the time make responses with these codes, such as
redirects, cacheable as wellcache_turbo_preset — selects a set of caching parameters,
including the freshness time and the length of the stale period:
micro, conservative, balanced (the default), or
aggressivecache_turbo_key — sets the cache key; by default, the key is the
host name and the request URI exactly as the client sent itcache_turbo_bypass — skips the cache lookup when any of the listed
values is neither empty nor 0, but still stores the backend responsecache_turbo_no_store — does not store the response under the same
condition; to keep personal pages out of the cache, list the same values in
both directivescache_turbo_backend — enables built-in rules for a CMS such as
WordPress or Drupal: requests from logged-in users, requests for admin
pages, and other dynamic requests bypass the cachecache_turbo_use_stale, cache_turbo_keep_stale — set which
backend failures let Angie serve a stale copy, and how long after a copy
stops being fresh it can still be served this waycache_turbo_admin — turns a location into the admin endpoint
of a zone. A GET request to it returns statistics in JSON, or in the
Prometheus format with ?format=prometheus; a POST request with
?key=, ?tag=, or ?all=1 purges cached copiescache_turbo_purge — allows purging the copy of a URI with a
PURGE request to that URIcache_turbo_redis, cache_turbo_memcached — add a shared
cache tier in Redis or memcached (see Using Redis)cache_turbo_tag — sets the tags of a stored copy, so that all copies
with a tag can be purged at once$cache_turbo_status — the cache outcome of the request, such as
HIT, STALE, or MISS; useful in the access log$cache_turbo_normalized_args — the query string with tracking
parameters removed and the remaining arguments sorted; meant for use in
cache_turbo_keyLoading the Module#
main{} context:load_module modules/ngx_http_cache_turbo_module.so;
Configuration Example#
http {
cache_turbo_zone name=pages 64m;
server {
listen 80;
location / {
cache_turbo pages;
cache_turbo_valid 10s;
cache_turbo_key $host$uri$cache_turbo_normalized_args;
proxy_pass http://127.0.0.1:8080;
}
location = /_cache {
cache_turbo_admin pages;
allow 127.0.0.1;
deny all;
}
}
# Backend
server {
listen 127.0.0.1:8080;
location / {
return 200 "Generated at $time_iso8601\n";
}
}
}
pages zone of
64 megabytes. A copy is fresh for 10 seconds, as cache_turbo_valid
sets; the default balanced preset then serves it as stale for three
times as long, 30 seconds. After that, the next request for the page goes to
the backend. The key is made of the host name, the path, and the normalized
query arguments, so /news/?utm_source=mail and /news/ share
one copy./_cache location is the admin endpoint of the zone. Restrict
access to it, as allow and deny do here: anyone who can reach
it can purge the cache. The second server stands in for the backend and
returns the time it generated the page.Demonstration#
X-Cache header:$ curl -s -D - 'http://localhost/news/?utm_source=mail'
HTTP/1.1 200 OK
...
Generated at 2026-11-20T09:18:43+00:00
X-Cache: HIT header marks a fresh copy,
and Age gives its age in seconds:$ curl -s -D - http://localhost/news/
HTTP/1.1 200 OK
...
Age: 0
X-Cache: HIT
...
Generated at 2026-11-20T09:18:43+00:00
X-Cache: STALE:$ sleep 12
$ curl -s -D - http://localhost/news/
HTTP/1.1 200 OK
...
Age: 12
X-Cache: STALE
...
Generated at 2026-11-20T09:18:43+00:00
$ curl -s -X POST 'http://localhost/_cache?key=localhost/news/'
{"purged":1}
$ curl -s -D - http://localhost/news/
HTTP/1.1 200 OK
...
Generated at 2026-11-20T09:18:55+00:00
Using Redis#
cache_turbo_redis directive adds a cache tier in Redis that
several Angie servers share. When a page is missing from the server's own
zone, Angie looks for it in Redis before going to the backend, and every copy
Angie stores also goes to Redis. A page cached by one server is then served by
the others.cache_turbo_tag sets the
tags of a stored copy, and Redis keeps the list of copies for each tag. In
this variant of the example, the backend marks news pages with the
X-Cache-Tags header, and the module reads the tags from it:http {
cache_turbo_zone name=pages 64m;
cache_turbo_redis 127.0.0.1:6379;
server {
...
location / {
...
cache_turbo_tag $upstream_http_x_cache_tags;
proxy_pass http://127.0.0.1:8080;
}
}
# Backend
server {
...
location /news/ {
add_header X-Cache-Tags news;
return 200 "Generated at $time_iso8601\n";
}
}
}
news tag removes the two news pages from the zone and from Redis; the
copy of /about stays:$ curl -s -o /dev/null http://localhost/news/1
$ curl -s -o /dev/null http://localhost/news/2
$ curl -s -o /dev/null http://localhost/about
$ curl -s -X POST 'http://localhost/_cache?tag=news'
{"purged":2}
$ curl -s -o /dev/null -D - http://localhost/about | grep X-Cache
X-Cache: HIT
cache_turbo_redis directive also accepts a password, a database
number, and TLS settings. The cache_turbo_memcached directive adds
the same tier in memcached instead, but without purging by tag.Additional Information#