Bird
Raised Fist0
Azurecloud~10 mins

CDN caching rules in Azure - Step-by-Step Execution

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Process Flow - CDN caching rules
Client Request
↓
Check CDN Cache
↓
Forward to Origin
↓
Origin Response
↓
Serve Cached Content
↓
Cache Content
↓
Apply Caching Rules
↓
Store/Update Cache
The CDN receives a client request, checks if content is cached, serves cached content if available, otherwise fetches from origin, applies caching rules, and updates the cache.
Execution Sample
Azure
1. Client requests /image.png
2. CDN checks cache for /image.png
3. Cache miss, CDN requests origin
4. Origin returns /image.png with Cache-Control: max-age=3600
5. CDN caches content for 3600 seconds
6. CDN serves /image.png to client
This example shows how a CDN handles a request, applies caching rules from origin headers, caches content, and serves it.
Process Table
StepActionCache StatusCaching Rule AppliedResult
1Client requests /image.pngN/AN/ARequest received by CDN
2CDN checks cache for /image.pngMissN/ANo cached content found
3CDN forwards request to originMissN/ARequest sent to origin server
4Origin responds with /image.png and Cache-Control: max-age=3600Missmax-age=3600CDN reads caching rule
5CDN caches /image.png for 3600 secondsCachedmax-age=3600Content stored in CDN cache
6CDN serves /image.png to clientCachedmax-age=3600Client receives cached content
7Client requests /image.png again within 3600 secondsHitmax-age=3600CDN serves cached content directly
8Client requests /image.png after 3600 secondsExpiredmax-age=3600Cache expired, CDN fetches from origin again
💡 Execution stops when content is served from cache or origin, depending on cache status and rules.
Status Tracker
VariableStartAfter Step 2After Step 5After Step 7After Step 8
Cache StatusEmptyMissCachedHitExpired
Cached Content TTL (seconds)0036003600 (valid)0 (expired)
Key Moments - 3 Insights
Why does the CDN fetch content from the origin at step 3?
Because the cache status is 'Miss' at step 2, meaning the content is not yet stored in the CDN cache, so it must request it from the origin.
What does the 'max-age=3600' caching rule mean at step 4?
It tells the CDN to keep the content cached for 3600 seconds (1 hour) before considering it expired and needing to fetch fresh content.
Why does the cache status change to 'Expired' at step 8?
Because the cached content's TTL of 3600 seconds has passed, so the CDN must fetch the content from the origin again to update the cache.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the cache status at step 5?
AMiss
BCached
CExpired
DHit
💡 Hint
Refer to the 'Cache Status' column in the execution table at step 5.
At which step does the CDN serve cached content directly to the client?
AStep 3
BStep 6
CStep 7
DStep 8
💡 Hint
Check the 'Result' column for when cached content is served without origin fetch.
If the origin sent Cache-Control: max-age=0, how would the cache status at step 5 change?
AIt would be 'Cached' with TTL 0
BIt would be 'Hit'
CIt would be 'Miss' and never cache
DIt would be 'Expired' immediately
💡 Hint
Look at how max-age affects TTL and cache expiration in the variable tracker.
Concept Snapshot
CDN caching rules control how long content is stored at the CDN edge.
Client requests check cache first; if miss, CDN fetches from origin.
Cache-Control headers like max-age set caching duration.
Cached content is served directly until TTL expires.
Expired content triggers a fresh fetch from origin.
Full Transcript
When a client requests content, the CDN first checks if it has the content cached. If not, it requests the content from the origin server. The origin server responds with the content and caching instructions, such as max-age, which tells the CDN how long to keep the content cached. The CDN stores the content and serves it to the client. Subsequent requests within the max-age period are served directly from the cache, improving speed. Once the max-age expires, the CDN fetches fresh content from the origin again. This process ensures efficient delivery and up-to-date content.

Practice

(1/5)
1. What is the primary purpose of CDN caching rules in Azure CDN?
easy
A. To monitor server CPU usage
B. To encrypt data between client and server
C. To control how content is stored and served from CDN servers
D. To manage user authentication

Solution

  1. Step 1: Understand CDN caching rules

    CDN caching rules define how content is cached and delivered by CDN servers.
  2. Step 2: Identify the main goal

    The main goal is to improve speed and reduce load by controlling content storage and delivery.
  3. Final Answer:

    To control how content is stored and served from CDN servers -> Option C
  4. Quick Check:

    CDN caching rules = control content caching [OK]
Hint: Caching rules control content storage and delivery [OK]
Common Mistakes:
  • Confusing caching with encryption
  • Thinking caching manages authentication
  • Assuming caching monitors server CPU
2. Which Azure CDN caching rule syntax correctly sets a cache duration of 3600 seconds for all images?
easy
A. cache-duration: 3600; match: *.jpg, *.png
B. cache-control: max-age=3600; match: *.jpg, *.png
C. cache-control: max-age=3600; match: images/*
D. cache-duration: max-age=3600; match: images/*

Solution

  1. Step 1: Identify correct cache-control syntax

    Azure CDN uses 'cache-control: max-age=seconds' to set cache duration.
  2. Step 2: Match correct file patterns

    Images are matched by extensions like '*.jpg, *.png' not 'images/*'.
  3. Final Answer:

    cache-control: max-age=3600; match: *.jpg, *.png -> Option B
  4. Quick Check:

    cache-control max-age + correct pattern = cache-control: max-age=3600; match: *.jpg, *.png [OK]
Hint: Use 'cache-control: max-age' with file extensions for images [OK]
Common Mistakes:
  • Using 'cache-duration' instead of 'cache-control'
  • Using folder pattern 'images/*' instead of file extensions
  • Mixing syntax keywords incorrectly
3. Given this Azure CDN caching rule:
cache-control: max-age=0; match: /api/*
What will happen when a user requests /api/data?
medium
A. Content will be blocked by CDN
B. Content will be cached indefinitely
C. Content will be cached for 3600 seconds
D. Content will be cached for 0 seconds, forcing CDN to fetch fresh data every time

Solution

  1. Step 1: Interpret max-age=0 meaning

    max-age=0 means no caching; content is always fresh.
  2. Step 2: Apply rule to /api/* path

    Requests to /api/data match /api/*, so caching is disabled.
  3. Final Answer:

    Content will be cached for 0 seconds, forcing CDN to fetch fresh data every time -> Option D
  4. Quick Check:

    max-age=0 disables caching = Content will be cached for 0 seconds, forcing CDN to fetch fresh data every time [OK]
Hint: max-age=0 means no caching, always fresh content [OK]
Common Mistakes:
  • Assuming max-age=0 caches content indefinitely
  • Confusing path matching syntax
  • Thinking content is blocked
4. You wrote this Azure CDN caching rule:
cache-control max-age=600; match: *.css
But it does not work as expected. What is the error?
medium
A. Missing colon after 'cache-control'
B. Incorrect file extension pattern
C. max-age value too low
D. Match pattern should be a full URL

Solution

  1. Step 1: Check syntax for cache-control

    The correct syntax requires a colon after 'cache-control', like 'cache-control: max-age=600'.
  2. Step 2: Validate other parts

    File extension '*.css' is correct; max-age=600 is valid; match pattern does not require full URL.
  3. Final Answer:

    Missing colon after 'cache-control' -> Option A
  4. Quick Check:

    Syntax error: missing colon = Missing colon after 'cache-control' [OK]
Hint: Remember colon after 'cache-control:' in rules [OK]
Common Mistakes:
  • Omitting colon after 'cache-control'
  • Using wrong file patterns
  • Thinking max-age value causes failure
5. You want to optimize caching for a website with static images and dynamic API data. Which Azure CDN caching rules setup is best?
hard
A. Set cache-control: max-age=86400 for images (*.jpg, *.png) and cache-control: max-age=0 for API (/api/*)
B. Set cache-control: max-age=0 for all content
C. Set cache-control: max-age=3600 for all content
D. Set cache-control: max-age=86400 for API and cache-control: max-age=0 for images

Solution

  1. Step 1: Understand content types and caching needs

    Static images benefit from long caching (86400 seconds = 1 day). Dynamic API data needs fresh content, so max-age=0.
  2. Step 2: Match rules to content paths

    Apply long cache to image extensions (*.jpg, *.png) and no cache to API paths (/api/*).
  3. Final Answer:

    Set cache-control: max-age=86400 for images (*.jpg, *.png) and cache-control: max-age=0 for API (/api/*) -> Option A
  4. Quick Check:

    Static long cache + dynamic no cache = Set cache-control: max-age=86400 for images (*.jpg, *.png) and cache-control: max-age=0 for API (/api/*) [OK]
Hint: Long cache for static, no cache for dynamic content [OK]
Common Mistakes:
  • Caching dynamic API data too long
  • Not differentiating static and dynamic content
  • Reversing cache durations for content types