0
0
Nginxdevops~20 mins

Cache validity rules in Nginx - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Cache Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
1:30remaining
Cache validity with expires directive
What is the HTTP response header Expires value when the following nginx configuration is applied?

location /images/ {
  expires 10d;
}
AExpires header is set to 10 minutes from the response time
BExpires header is set to 10 seconds from the response time
CExpires header is not set by this configuration
DExpires header is set to 10 days from the response time
Attempts:
2 left
💡 Hint
The expires directive sets the cache duration relative to the response time.
🧠 Conceptual
intermediate
1:30remaining
Understanding cache-control max-age
Which statement correctly describes the effect of add_header Cache-Control "max-age=3600"; in nginx configuration?
AIt sets the cache to expire 3600 seconds after the response is received
BIt disables caching for the resource
CIt sets the cache to expire immediately
DIt sets the cache to expire after 3600 minutes
Attempts:
2 left
💡 Hint
max-age is measured in seconds.
Troubleshoot
advanced
2:00remaining
Diagnosing cache not expiring as expected
You configured nginx with expires 5m; but clients still receive cached content after 10 minutes. What is the most likely cause?
AThe upstream server is sending conflicting Cache-Control headers that override nginx
BThe <code>expires</code> directive only works for static files, not dynamic content
CThe <code>expires</code> directive requires a reload of nginx to take effect
DThe client browser ignores all cache headers by default
Attempts:
2 left
💡 Hint
Check headers sent by the backend server.
🔀 Workflow
advanced
2:00remaining
Configuring cache validity for API responses
You want to cache API responses for 30 seconds but ensure clients always revalidate after that. Which nginx configuration snippet achieves this?
Aexpires 30s; add_header Cache-Control "no-cache";
Bexpires 30s; add_header Cache-Control "public";
Cadd_header Cache-Control "max-age=30, must-revalidate";
Dadd_header Cache-Control "no-store";
Attempts:
2 left
💡 Hint
Use Cache-Control directives to control revalidation.
Best Practice
expert
2:30remaining
Best practice for cache validity with varying content
You serve images that rarely change and JSON data that updates frequently. What is the best cache validity strategy in nginx to optimize performance and freshness?
ASet the same expires time (e.g., 1d) for both images and JSON for simplicity
BSet long expires (e.g., 30d) for images and short max-age (e.g., 10s) with must-revalidate for JSON
CDisable caching for images and set long max-age for JSON
DUse no-store for both images and JSON to avoid caching issues
Attempts:
2 left
💡 Hint
Different content types need different cache durations.