Microcaching is a caching technique in which a server or reverse proxy stores dynamically generated responses for a very short period, typically between one and ten seconds, and serves that stored copy to every request that arrives during the window. In server performance work, it is valued because it turns hundreds of identical requests per second into a single backend render per interval, while keeping content fresh enough that most visitors never notice any delay in updates.
The approach is most often implemented in NGINX with proxy_cache or fastcgi_cache, in Varnish, or in a content delivery network edge, and it sits in front of application runtimes such as PHP, Python or Node.js on busy servers. It complements longer-lived full-page caching rather than replacing it.
How microcaching absorbs request bursts
Microcaching works by accepting a tiny window of staleness in exchange for a large reduction in backend work. When the first request for a URL arrives, the proxy forwards it to the application, stores the response with a time to live (TTL) of one second or similar, and answers every later request for that URL from memory until the entry expires.
The arithmetic explains the effect. If a homepage receives 500 requests per second, a one-second microcache reduces backend renders to roughly one per second per cache key, a reduction of more than 99 percent. Because each render is reused only briefly, editors and users see changes within seconds, which is why the method suits frequently updated but widely shared pages.
Two supporting mechanisms make the technique reliable under load. Request collapsing, called proxy_cache_lock in NGINX, allows only one request to populate an expired entry while others wait. Serving stale content, through proxy_cache_use_stale updating, lets the proxy return the previous copy while a single background request refreshes it, which prevents a cache stampede at every expiry.
The following table shows how the main components cooperate during a burst.
| Component | Role | Typical setting |
|---|---|---|
| Cache key | Identifies which responses are interchangeable | Scheme, host and URI |
| TTL | Defines how long a response is reused | 1 to 10 seconds |
| Cache lock | Lets one request refill an expired entry | Enabled, timeout about 5 s |
| Stale serving | Returns the old copy during refresh | On updating and on errors |
| Bypass rules | Exclude personalized or private traffic | Session cookies, POST requests |
Key parameters and how to tune them
The TTL is the central tuning decision because it sets the balance between freshness and offload. Shorter windows keep content nearly live but leave more renders; longer windows save more work but delay updates. For most dynamic sites, one to five seconds captures the bulk of the benefit, since load reduction grows quickly at first and then flattens.
Equally important is the definition of the cache key. A key that includes irrelevant query parameters, such as marketing tags, fragments the cache into many rarely reused entries. A key that omits a relevant variation, such as the language or device class, can serve the wrong variant to the wrong user, which is a correctness failure rather than a performance one.
The table below summarizes the parameters that operators adjust most often.
| Parameter | Effect of increasing it | Practical range |
|---|---|---|
| TTL | Higher offload, staler content | 1 to 10 s |
| Lock timeout | Fewer duplicate renders, longer waits | 2 to 10 s |
| Cache zone size | More keys held in memory | 10 to 500 MB |
| Key granularity | More variants, lower hit ratio | As few variants as correct |
| Stale tolerance | Better resilience during outages | Seconds to minutes |
Operators should also verify response headers that block caching. Applications often send Cache-Control: private or set cookies on every response, and many proxies skip storage in those cases unless they are explicitly configured to ignore or strip such headers for anonymous traffic.
Microcaching compared with related caching layers
Microcaching is best understood as a short-lived form of full-page caching placed at the HTTP layer. It differs from OPcache, which stores compiled PHP bytecode, and from an object cache, which stores database query results or computed fragments inside the application. These layers stack rather than compete, and a well-tuned server often uses all of them.
The comparison below clarifies where each layer acts and what it saves.
| Cache type | What it stores | Typical lifetime | Work it saves |
|---|---|---|---|
| Microcache | Complete HTTP responses | 1 to 10 s | Entire request processing |
| Full-page cache | Complete HTTP responses | Minutes to days | Entire request processing |
| Object cache | Query results and objects | Seconds to hours | Database round trips |
| OPcache | Compiled PHP bytecode | Until code changes | Script parsing and compilation |
The decisive advantage of microcaching over a long-lived full-page cache is that it needs little or no purge logic. Because entries expire within seconds, operators avoid complex invalidation rules, which makes the technique attractive for news feeds, live scores, product listings and API endpoints whose output changes often.
When to use microcaching and when to avoid it
Microcaching delivers the greatest value where many anonymous users request the same dynamic content at high rates. It is less useful for long-tail pages that receive one visit per minute, because almost every request finds an expired entry and the hit ratio stays low.
The decision table below helps match the technique to common situations.
| Situation | Recommendation | Reason |
|---|---|---|
| Viral article or homepage spike | Apply a 1 to 5 s microcache | Collapses identical requests |
| Logged-in dashboards | Bypass the cache | Responses are personalized |
| Checkout and payment pages | Never cache | Risk of leaking private data |
| Public JSON API with frequent reads | Apply with short TTL | Reduces backend queries |
| Rarely visited archive pages | Prefer a longer page cache | Microcache hit ratio stays low |
Capacity planners often treat microcaching as insurance against sudden traffic surges. A server that handles 50 requests per second through PHP workers can absorb thousands of requests per second for cached URLs, because serving from proxy memory costs microseconds instead of tens of milliseconds.
Risks, limitations and common mistakes
The most serious risk is caching personalized responses and serving them to other visitors. This happens when bypass rules miss a session cookie or an authorization header, and it can expose account names, shopping carts or private data. Strict bypass conditions for authenticated traffic are therefore mandatory.
- Ignoring Set-Cookie headers can store a session cookie and hand it to every visitor in the window.
- Caching error responses for the full TTL can turn a brief backend failure into a visible outage.
- Overly broad cache keys reduce the hit ratio and waste memory on duplicates.
- Missing cache locks allow many simultaneous renders at expiry, recreating the original overload.
- Unmonitored hit ratios hide misconfiguration; the
X-Cache-Statusheader makes behavior visible.
Microcaching also cannot fix slow pages for the first visitor in each window. Tail latency for that request remains unchanged, so backend optimization still matters, especially for pages whose traffic is too sparse to benefit from short-lived reuse.
In simple terms
Imagine a busy café where fifty customers order the same coffee in the same minute. Instead of brewing fifty separate cups from scratch, the barista brews one large pot and pours from it until it runs out a moment later. Microcaching does the same for web pages: the server builds a page once and hands that copy to everyone who asks within the next second or two.
Visitors still get nearly fresh content, because the copy is replaced constantly. The server, however, does a tiny fraction of the work. The key point is simple: a very short memory turns a flood of identical requests into a trickle.
A practical example
A regional news site runs WordPress behind NGINX on a single server with 16 PHP workers, which comfortably handle about 60 uncached page views per second. During an election night, a results page receives roughly 1,800 requests per second, and response times climb past ten seconds as the worker pool saturates.
The operations team enables a two-second fastcgi_cache microcache for anonymous visitors, adds a cache lock and stale serving during updates, and bypasses the cache for anyone with a WordPress login cookie. Backend renders for the results page fall to about one every two seconds, CPU usage drops from 100 percent to roughly 25 percent, and the median response time returns to under 100 milliseconds. Editors still see their updates published to readers within two seconds.