0
0
Nginxdevops~10 mins

Micro-caching for dynamic content in Nginx - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to enable micro-caching for 1 second in nginx.

Nginx
proxy_cache_path /tmp/cache keys_zone=microcache:10m max_size=100m inactive=60m;

server {
    location / {
        proxy_cache microcache;
        proxy_cache_valid 200 [1]s;
        proxy_pass http://backend;
    }
}
Drag options to blanks, or click blank then click option'
A60
B10
C1
D30
Attempts:
3 left
💡 Hint
Common Mistakes
Setting cache time too long, which defeats micro-caching purpose.
Using zero or negative values causing errors.
2fill in blank
medium

Complete the code to bypass cache for logged-in users based on a cookie.

Nginx
server {
    location / {
        proxy_cache microcache;
        proxy_cache_bypass [1];
        proxy_pass http://backend;
    }
}
Drag options to blanks, or click blank then click option'
A$http_cookie ~* "logged_in"
B$cookie_logged_in
C$cookie_user
D$http_logged_in
Attempts:
3 left
💡 Hint
Common Mistakes
Using undefined variables like $http_logged_in.
Not using regex match operator for cookie string.
3fill in blank
hard

Fix the error in the micro-cache key definition to include the request URI.

Nginx
proxy_cache_key [1];
Drag options to blanks, or click blank then click option'
A$scheme_host$request_uri
B$scheme$host$uri
C$host$request_uri
D$scheme$host$request_uri
Attempts:
3 left
💡 Hint
Common Mistakes
Using undefined variables like $scheme_host.
Using $uri which excludes query parameters.
4fill in blank
hard

Fill both blanks to set cache control headers and enable micro-caching for 2 seconds.

Nginx
server {
    location / {
        add_header Cache-Control "public, max-age=[1]";
        proxy_cache_valid 200 [2]s;
        proxy_cache microcache;
        proxy_pass http://backend;
    }
}
Drag options to blanks, or click blank then click option'
A2
B1
D5
Attempts:
3 left
💡 Hint
Common Mistakes
Using different values causing cache headers and proxy cache to mismatch.
Setting too long max-age for micro-caching.
5fill in blank
hard

Fill all three blanks to create a micro-cache zone, set cache key, and bypass cache for POST requests.

Nginx
proxy_cache_path /tmp/microcache keys_zone=[1]:10m max_size=50m inactive=1h;

server {
    location /api/ {
        proxy_cache [2];
        proxy_cache_key [3];
        proxy_cache_bypass $request_method = POST;
        proxy_pass http://backend_api;
    }
}
Drag options to blanks, or click blank then click option'
Amicrocache
B$scheme$host$request_uri
C$host$request_uri
Dcache_zone
Attempts:
3 left
💡 Hint
Common Mistakes
Using different zone names causing cache errors.
Using incomplete cache keys missing query parameters.