Purging CDN cache in Azure - Time & Space Complexity
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?"