Purging CDN cache in Azure - Time & Space Complexity
Start learning this pattern below
Jump into concepts and practice - no test required
When we purge a CDN cache, we ask the system to remove stored copies of content so fresh content can be served.
We want to know how the time to complete this purge changes as we ask to clear more items.
Analyze the time complexity of the following operation sequence.
// Purge multiple CDN paths
var cdnClient = new CdnManagementClient(credentials);
var purgeContentPaths = new List<string> { "/images/*", "/css/*", "/js/*" };
await cdnClient.Endpoints.PurgeContentAsync(
resourceGroupName, profileName, endpointName, purgeContentPaths);
This code sends a request to purge multiple paths from the CDN cache at once.
Identify the API calls, resource provisioning, data transfers that repeat.
- Primary operation: One API call to purge multiple paths.
- How many times: The purge API is called once per purge request, regardless of number of paths.
Adding more paths to purge does not increase the number of API calls, but may increase the request size slightly.
| Input Size (n) | Approx. Api Calls/Operations |
|---|---|
| 10 | 1 API call |
| 100 | 1 API call |
| 1000 | 1 API call |
Pattern observation: The number of API calls stays the same even as the number of paths grows.
Time Complexity: O(1)
This means the time to send the purge request does not grow with the number of paths purged.
[X] Wrong: "Purging more paths means more API calls and longer time."
[OK] Correct: The purge API accepts multiple paths in one call, so the number of calls stays the same regardless of paths.
Understanding how cloud APIs handle batch operations helps you design efficient systems and answer questions about scaling in real projects.
"What if we purged each path with a separate API call? How would the time complexity change?"
Practice
Solution
Step 1: Understand CDN cache role
CDN caches store copies of content to serve users faster.Step 2: Purpose of purging cache
Purging removes old cached content so fresh content is served.Final Answer:
To remove outdated content so users get the latest version -> Option BQuick Check:
Purging = Remove outdated content [OK]
- Thinking purging adds content instead of removing
- Confusing purging with monitoring or scaling
- Believing purging increases storage capacity
Solution
Step 1: Identify correct command for purging
The command to purge cache isaz cdn endpoint purge.Step 2: Check parameters
It requires resource group, profile name, endpoint name, and content paths.Final Answer:
az cdn endpoint purge --resource-group MyGroup --profile-name MyProfile --name MyEndpoint --content-paths '/images/*' -> Option AQuick Check:
Purging usesaz cdn endpoint purge[OK]
- Using 'create' or 'start' commands instead of 'purge'
- Confusing profile purge with endpoint purge
- Omitting required parameters like endpoint name
az cdn endpoint purge --resource-group RG1 --profile-name Profile1 --name Endpoint1 --content-paths '/css/*' '/js/app.js'What will happen after running it?
Solution
Step 1: Analyze content-paths parameter
The command lists two paths: '/css/*' and '/js/app.js'. Both are valid and separated by space.Step 2: Understand purge effect
Both specified paths will be purged from the CDN cache after command runs.Final Answer:
Both '/css/*' and '/js/app.js' files will be purged from the CDN cache -> Option CQuick Check:
Multiple paths purge all listed [OK]
- Assuming only first path is purged
- Thinking command syntax is invalid with multiple paths
- Believing wildcard and file path cannot be combined
az cdn endpoint purge --resource-group RG1 --profile-name Profile1 --name Endpoint1 --content-paths '/images/logo.png'But the cache is not cleared. What is the most likely cause?
Solution
Step 1: Check command correctness
The command syntax is correct and supports purging images.Step 2: Identify common purge failure reason
If cache is not cleared, often the content path does not match cached files exactly.Final Answer:
The content path is incorrect or does not match cached files -> Option AQuick Check:
Incorrect path = purge fails [OK]
- Assuming CLI cannot purge images
- Ignoring typos in resource group or endpoint names
- Thinking purge works instantly without matching paths
Solution
Step 1: Understand impact of purging scope
Purging entire endpoint cache causes high load and delays for all users.Step 2: Choose targeted purging
Purging only the specific JavaScript file updates that content with minimal performance impact.Final Answer:
Purge only the specific JavaScript file path instead of the entire CDN endpoint -> Option DQuick Check:
Targeted purge = minimal impact [OK]
- Purging entire cache too often causing slowdowns
- Disabling caching loses CDN benefits
- Purging too rarely causing stale content
