Interview Prep/Networking/Load Balancing, Proxies & nginx in Production

How do you configure nginx microcaching for dynamic content?

IntermediateProductionLoad Balancing, Proxies & nginx in Production
Answer
proxy_cache_path /var/cache/nginx keys_zone=micro:10m max_size=1g inactive=10m;
location / {
  proxy_cache micro;
  proxy_cache_valid 200 1s;
  proxy_cache_lock on;
  proxy_cache_use_stale updating;
  add_header X-Cache $upstream_cache_status;
  proxy_pass http://app;
}

A 1-second cache turns a thousand requests per second for the same URL into one backend hit, only for content safe to share across users.

All Networking questions Roadmap: Networking for DevOps

More on Load Balancing, Proxies & nginx in Production