0
0
Azurecloud~10 mins

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

Choose your learning style9 modes available
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.