Micro-cache
The micro-cache keeps every successful page of a site or Docker app in nginx for a few seconds (1 to 10, default 1). During a spike, hundreds of identical requests per second become one request to your app per interval, while visitors never see a page older than that. It is off by default, set per site or per app, and available on all plans. It needs agent 0.2.166 or newer.
It covers PHP / Laravel / Symfony, Node.js, Python and Go sites and Docker apps. WordPress sites have the full page cache instead; static sites are already served straight from disk.
Turn it on, step by step
Section titled “Turn it on, step by step”- Open the server’s Sites list and press Manage on the site.
- PHP site: the Tools tab.
- Node.js / Python / Go site: the Runtime tab.
- Docker app: open the app (Containers tab) and scroll to its Domains section.
- In the Micro-cache card, switch on Micro-cache pages for a few seconds.
- Pick Keep pages for (1, 2, 3, 5 or 10 seconds). Visitors may see a page up to that old.
- Leave Cache URLs with a query string off unless your query strings never carry anything personal (search, filters and tokens usually do).
Check it from your machine: the second request within the interval answers
X-MZ-Cache: HIT.
curl -sI https://example.com/ | grep -i x-mz-cache # MISScurl -sI https://example.com/ | grep -i x-mz-cache # HITWhat is never cached
Section titled “What is never cached”The cache is conservative on purpose. nginx always passes these to your app:
- any request that is not
GETorHEAD; - any request with a cookie (any cookie at all, so sessions and logins are safe) or an
Authorizationheader; - any URL with a query string, unless you turned query caching on;
- WebSocket upgrades (apps and runtime sites).
And it never stores:
- a response that sets a cookie (
Set-Cookie); - a response with
Cache-Control: private,no-store,no-cache,max-age=0ors-maxage=0; - anything but a
200(redirects, 404s and errors always reach your app).
Your app’s own Cache-Control, Expires and X-Accel-Expires cannot make a page live
longer than the interval you picked. They still reach browsers and Cloudflare unchanged:
the micro-cache adds no Cache-Control header.
How it works
Section titled “How it works”- One refill at a time. When an entry expires, one request refreshes it and the others
get the previous copy (
X-MZ-Cache: STALEorUPDATING) instead of all hitting the app. If the app is down or times out, the last good copy is served for up to 10 minutes. - Sites get a small nginx snippet in the site’s include directory, so certificate renewals and vhost re-renders keep the setting. Deleting the site removes it.
- Docker apps get the cache inside every domain’s proxy block. Responses are buffered
while it is on: an app that streams (server-sent events, long polling) should send
X-Accel-Buffering: noon those responses. Turning the cache off restores the app’s vhost exactly as it was. - Every change is checked with
nginx -tfirst and rolled back if nginx rejects it. - Status header values:
HIT,MISS,BYPASS(one of the rules above),EXPIRED,STALE,UPDATING. A response without the header was not eligible (for example aPOST).
CLI & automation
Section titled “CLI & automation”mz site microcache example.com --json # read the settingmz site microcache example.com --ttl 5 --json # on, 5 secondsmz site microcache example.com --ttl 2 --query cache --json # also cache query stringsmz site microcache example.com --off --jsonmz app microcache myapp --ttl 1 --json # a Docker app, every domainAutomate it (MCP / REST)
Section titled “Automate it (MCP / REST)”Both are async jobs (jobs_create over MCP, POST /v1/servers/{id}/jobs over REST), on
every plan. Leave out enabled to read the state.
| Goal | Job body |
|---|---|
| Read a site’s setting | {"type": "site.microcache", "domain": "example.com"} |
| Turn it on for a site | {"type": "site.microcache", "domain": "example.com", "enabled": true, "ttl": 5} |
| Also cache query strings | {"type": "site.microcache", "domain": "example.com", "enabled": true, "ttl": 2, "query": "cache"} |
| Turn it off | {"type": "site.microcache", "domain": "example.com", "enabled": false} |
| A Docker app | {"type": "app.microcache", "name": "myapp", "enabled": true, "ttl": 1} |
ttl is 1 to 10 seconds (default 1); query is bypass (default) or cache. The job
answers {enabled, ttl, query, engine: "fastcgi"|"proxy", header: "X-MZ-Cache", changed}.
Gotchas & troubleshooting
Section titled “Gotchas & troubleshooting”| Code | Meaning | Fix |
|---|---|---|
unsupported_type | The site is WordPress (use the page cache) or static (nothing to cache) | Nothing to do |
unsupported_vhost | The app’s nginx vhost was edited by hand and has no standard proxy block | Re-add the app’s domain to regenerate the vhost, then retry |
no_domain | The app has no domain yet | Add a domain first |
nginx_test_failed | nginx rejected the change; it was rolled back | Run nginx -t on the box |
exit 127 | Agent older than 0.2.166 | Update the agent |
- Always
BYPASS? Your browser sends a cookie (analytics, a consent banner, a session). Any cookie bypasses the cache; test withcurl, which sends none. - Never
HIT, alwaysMISS? The app sets a cookie on every response or sendsCache-Control: private/no-cache. That is the app telling nginx not to cache. - Pages a few seconds behind after a deploy? Expected: they refresh within the interval.
Related
Section titled “Related”- Site tools — the Manage drawer where the card lives.
- Apps (Docker) — app domains and settings.
- Optimize & cache — the WordPress page cache.