How can we serve 10,000 users per second without our server even breaking a sweat?
By the end of this lesson, students will be able to:
NGINX caching is a process where NGINX, acting as a reverse proxy, stores a copy of a response from a backend server. For subsequent identical requests, NGINX serves the stored copy directly, drastically reducing latency and server load.
This is the foundational directive. Defined in the `http` block, it configures the on-disk storage path for cached files and, crucially, creates a shared memory zone to hold cache keys and metadata. Its parameters control the cache's size, structure, and behavior.
You need fine-grained control over caching. Directives like proxy_cache enable it for a location, proxy_cache_valid sets default lifetimes, and proxy_cache_bypass provides a way to conditionally ignore the cache, for example, for logged-in users.
Caching private data is dangerous. By default, NGINX uses the URL as the cache key, which can leak one user's data to another. To cache authenticated content safely, you must use proxy_cache_key to include a user-specific identifier, like a session cookie.
The "thundering herd" problem occurs when a popular, expired item is requested by many users at once, overwhelming your backend. proxy_cache_lock solves this by allowing only the first request to go to the backend, while others wait for the cache to be filled.
What if your backend server fails? Instead of showing an error, NGINX can serve an expired ("stale") version of the content from its cache. This directive dramatically improves user experience and site resilience during outages or high load.
True or False?
Describe a scenario where `proxy_cache_bypass` would be more appropriate than using a custom `proxy_cache_key`.