Cache and microcaching
A cache is a storage layer that keeps the results of expensive work — rendered pages, database query results, API responses — so subsequent requests can be answered instantly instead of recomputing the same output. Microcaching is a specialised form of it: caching fully dynamic responses for a very short time, typically between one and ten seconds.
How caching and microcaching work
Caching happens at several layers of the stack, each one offloading the layers behind it:
- Browser cache — static assets kept locally according to the Cache-Control header;
- Edge and proxy cache — a CDN, Varnish or Nginx reverse proxy storing whole HTTP responses;
- Application cache — objects and query results held in Redis or Memcached;
- Opcode cache — compiled PHP bytecode reused by OPcache.
Microcaching lives at the reverse-proxy layer. The first request in a time window hits the backend and the generated page is stored; every following request within, say, five seconds is served straight from memory. Two supporting mechanisms matter in production: cache locking (only one request regenerates an expired entry while others wait or receive the stale copy) and bypass rules that exclude logged-in users, carts and other personalised responses from the shared cache.
Practical use cases
Microcaching shines on high-traffic dynamic sites with mostly anonymous visitors — news portals, blogs, product catalogues, event pages. Content still refreshes every few seconds, yet the application server renders each page a handful of times per minute regardless of how many thousands of visitors arrive. It also acts as a cheap shock absorber for viral traffic spikes, buying time before autoscaling or manual capacity changes kick in.
On a typical VPS or managed server this is implemented with Nginx's proxy_cache or fastcgi_cache directives; full-page caching plugins in CMSs complement it by producing static HTML. The best results come from combining layers: microcache protects the backend globally, while application-level caching accelerates the specific queries that remain expensive.
Powiązane pojęcia
Najczęstsze pytania
Is a few seconds of microcache really worth it?
Yes — the maths is dramatic. At 300 requests per second, a 5-second microcache means the backend renders the page once per window instead of 1,500 times. Users still see content that is at most a few seconds old, which is acceptable for most public pages.
