Skip to content
Micro-cache An opt-in nginx cache that keeps each page of a PHP, Node.js, Python or Go site, or a Docker app, for 1 to 10 seconds, so a traffic spike reaches the app once per interval instead of once per visitor.

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.

  1. 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.
  2. In the Micro-cache card, switch on Micro-cache pages for a few seconds.
  3. Pick Keep pages for (1, 2, 3, 5 or 10 seconds). Visitors may see a page up to that old.
  4. 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.

Terminal window
curl -sI https://example.com/ | grep -i x-mz-cache # MISS
curl -sI https://example.com/ | grep -i x-mz-cache # HIT

The cache is conservative on purpose. nginx always passes these to your app:

  • any request that is not GET or HEAD;
  • any request with a cookie (any cookie at all, so sessions and logins are safe) or an Authorization header;
  • 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=0 or s-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.

  • One refill at a time. When an entry expires, one request refreshes it and the others get the previous copy (X-MZ-Cache: STALE or UPDATING) 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: no on those responses. Turning the cache off restores the app’s vhost exactly as it was.
  • Every change is checked with nginx -t first 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 a POST).
Terminal window
mz site microcache example.com --json # read the setting
mz site microcache example.com --ttl 5 --json # on, 5 seconds
mz site microcache example.com --ttl 2 --query cache --json # also cache query strings
mz site microcache example.com --off --json
mz app microcache myapp --ttl 1 --json # a Docker app, every domain

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.

GoalJob 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}.

CodeMeaningFix
unsupported_typeThe site is WordPress (use the page cache) or static (nothing to cache)Nothing to do
unsupported_vhostThe app’s nginx vhost was edited by hand and has no standard proxy blockRe-add the app’s domain to regenerate the vhost, then retry
no_domainThe app has no domain yetAdd a domain first
nginx_test_failednginx rejected the change; it was rolled backRun nginx -t on the box
exit 127Agent older than 0.2.166Update the agent
  • Always BYPASS? Your browser sends a cookie (analytics, a consent banner, a session). Any cookie bypasses the cache; test with curl, which sends none.
  • Never HIT, always MISS? The app sets a cookie on every response or sends Cache-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.