Bird
Raised Fist0
Rest APIprogramming~20 mins

Cache-Control header directives in Rest API - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Cache-Control Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
What is the effect of this Cache-Control header?
Given the HTTP response header:
Cache-Control: no-store

What will the browser do with the response?
AThe browser will cache the response but revalidate it on every request.
BThe browser will cache the response and serve it without revalidation until it expires.
CThe browser will store the response only if it is marked as public.
DThe browser will not store the response in any cache and will fetch it fresh every time.
Attempts:
2 left
💡 Hint
Think about what 'no-store' means for caching behavior.
❓ Predict Output
intermediate
2:00remaining
What is the output of this Cache-Control header?
Consider this HTTP response header:
Cache-Control: max-age=3600, must-revalidate

What does this mean for the cached response?
AThe response can be served from cache for 3600 seconds, but after that it must be revalidated before use.
BThe response must be revalidated with the server before every use, ignoring max-age.
CThe response can be served from cache for up to 3600 seconds without checking with the server.
DThe response is cached indefinitely and never revalidated.
Attempts:
2 left
💡 Hint
Consider how max-age and must-revalidate work together.
🔧 Debug
advanced
2:00remaining
Identify the error in this Cache-Control header
A developer wrote this Cache-Control header:
Cache-Control: max-age=abc, public

What error will this cause?
AThe header will cache the response for 0 seconds.
BThe header will cause a server error and the response will not be sent.
CThe header will be ignored because max-age value is invalid (not a number).
DThe header will cache the response indefinitely because max-age is ignored.
Attempts:
2 left
💡 Hint
Check the format required for max-age values.
🧠 Conceptual
advanced
2:00remaining
Which Cache-Control directive allows shared caches but prevents private caches?
Which Cache-Control directive below allows caching by shared caches (like proxies)?
Aprivate
Bpublic
Cno-cache
Dno-store
Attempts:
2 left
💡 Hint
Think about which directive marks a response as cacheable by any cache.
❓ Predict Output
expert
2:00remaining
What is the number of directives in this Cache-Control header?
Count the number of valid directives in this Cache-Control header:
Cache-Control: no-cache, max-age=600, private, must-revalidate, proxy-revalidate
A5
B4
C3
D6
Attempts:
2 left
💡 Hint
Count each directive separated by commas.

Practice

(1/5)
1. What does the Cache-Control: no-store directive instruct browsers to do?
easy
A. Not to save any part of the response in cache
B. Allow caching but revalidate before use
C. Cache the response for a specified time
D. Cache the response only if it is public

Solution

  1. Step 1: Understand the meaning of no-store

    The no-store directive means the browser must not save any part of the response in cache.
  2. Step 2: Compare with other directives

    Unlike no-cache which allows caching but requires revalidation, no-store forbids storing at all.
  3. Final Answer:

    Not to save any part of the response in cache -> Option A
  4. Quick Check:

    no-store means no saving [OK]
Hint: No-store means do not save anything at all [OK]
Common Mistakes:
  • Confusing no-store with no-cache
  • Thinking no-store allows caching with revalidation
  • Assuming no-store caches for a short time
2. Which of the following is the correct syntax to set a Cache-Control header that caches content for 3600 seconds?
easy
A. Cache-Control: max-age=3600
B. Cache-Control: maxage:3600
C. Cache-Control: max_age=3600
D. Cache-Control: max-age:3600

Solution

  1. Step 1: Recall correct Cache-Control syntax

    The correct syntax uses a hyphen and equals sign: max-age=3600.
  2. Step 2: Identify incorrect options

    Options with colon or underscore instead of equals or hyphen are invalid syntax.
  3. Final Answer:

    Cache-Control: max-age=3600 -> Option A
  4. Quick Check:

    Use hyphen and equals for max-age [OK]
Hint: Use hyphen and equals sign for max-age [OK]
Common Mistakes:
  • Using colon instead of equals
  • Replacing hyphen with underscore
  • Omitting equals sign
3. Given the header Cache-Control: public, max-age=600, what will happen when a browser receives this response?
medium
A. The response will be cached privately for 10 minutes
B. The response will not be cached at all
C. The response will be cached and shared by any user for 10 minutes
D. The response will be cached but must be revalidated every time

Solution

  1. Step 1: Understand the public directive

    public means the response can be cached by any cache, including shared caches.
  2. Step 2: Interpret max-age=600

    This means the cached response is fresh for 600 seconds (10 minutes) without revalidation.
  3. Final Answer:

    The response will be cached and shared by any user for 10 minutes -> Option C
  4. Quick Check:

    public + max-age=600 means shared cache for 10 minutes [OK]
Hint: Public means shared cache; max-age sets cache time [OK]
Common Mistakes:
  • Thinking public means private caching
  • Confusing max-age with no-cache
  • Assuming revalidation is always required
4. You see this Cache-Control header in a response: Cache-Control: no-cache, max-age=3600. What is wrong with this header?
medium
A. The syntax is invalid because directives cannot be combined
B. The no-cache directive conflicts with max-age and disables caching
C. There is no error; this header caches for 3600 seconds
D. The max-age value must be zero when no-cache is used

Solution

  1. Step 1: Understand no-cache directive

    no-cache means the cache must revalidate before using the cached response.
  2. Step 2: Analyze conflict with max-age=3600

    max-age=3600 says the response is fresh for 3600 seconds, but no-cache forces revalidation, effectively disabling caching without validation.
  3. Final Answer:

    The no-cache directive conflicts with max-age and disables caching -> Option B
  4. Quick Check:

    no-cache overrides max-age freshness [OK]
Hint: No-cache forces revalidation, ignoring max-age freshness [OK]
Common Mistakes:
  • Thinking directives cannot be combined
  • Assuming max-age always overrides no-cache
  • Believing no-cache disables caching completely
5. You want to ensure a sensitive API response is never stored by browsers or intermediate caches. Which Cache-Control header should you use?
hard
A. Cache-Control: no-store, no-cache
B. Cache-Control: private, max-age=0
C. Cache-Control: public, max-age=0
D. Cache-Control: no-store

Solution

  1. Step 1: Identify directive that prevents any storage

    no-store tells browsers and caches not to store the response anywhere.
  2. Step 2: Compare with other options

    no-cache allows storing but requires revalidation; private allows browser-only caching; public allows shared caching.
  3. Final Answer:

    Cache-Control: no-store -> Option D
  4. Quick Check:

    no-store forbids all storage [OK]
Hint: Use no-store to block all caching and storage [OK]
Common Mistakes:
  • Using no-cache instead of no-store
  • Assuming private disables all caching
  • Setting max-age=0 without no-store
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard