Microcaching

On this page 7

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.

ComponentRoleTypical setting
Cache keyIdentifies which responses are interchangeableScheme, host and URI
TTLDefines how long a response is reused1 to 10 seconds
Cache lockLets one request refill an expired entryEnabled, timeout about 5 s
Stale servingReturns the old copy during refreshOn updating and on errors
Bypass rulesExclude personalized or private trafficSession cookies, POST requests
Components of a microcaching setup

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.

ParameterEffect of increasing itPractical range
TTLHigher offload, staler content1 to 10 s
Lock timeoutFewer duplicate renders, longer waits2 to 10 s
Cache zone sizeMore keys held in memory10 to 500 MB
Key granularityMore variants, lower hit ratioAs few variants as correct
Stale toleranceBetter resilience during outagesSeconds to minutes
Microcaching parameters and their effects

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 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 typeWhat it storesTypical lifetimeWork it saves
MicrocacheComplete HTTP responses1 to 10 sEntire request processing
Full-page cacheComplete HTTP responsesMinutes to daysEntire request processing
Object cacheQuery results and objectsSeconds to hoursDatabase round trips
OPcacheCompiled PHP bytecodeUntil code changesScript parsing and compilation
Microcaching and neighboring cache types

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.

SituationRecommendationReason
Viral article or homepage spikeApply a 1 to 5 s microcacheCollapses identical requests
Logged-in dashboardsBypass the cacheResponses are personalized
Checkout and payment pagesNever cacheRisk of leaking private data
Public JSON API with frequent readsApply with short TTLReduces backend queries
Rarely visited archive pagesPrefer a longer page cacheMicrocache hit ratio stays low
Deciding whether to apply microcaching

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-Status header 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.