{tocify} $title={Table of Contents}
CDN Purge cache:
Azure
CDN is efficient for static websites which can store the content in nearby CDN
servers cached values so that the website is faster in response for users. So,
if we have updated the content in the storage account where the Azure CDN is
pointed to then we must purge or refresh the cached contents in the Azure CDN
servers so that all the users are getting updated files.
We
can purge the Azure CDN content using the following comment using Azure CLI:
az cdn endpoint purge --content-paths
[--ids]
[--name]
[--no-wait]
[--profile-name]
[--resource-group]
[--subscription]
Required Parameters
• --content-paths
The path to the content to be purged. Can describe a file path or a wildcard
directory.
Optional
Parameters
• --ids
One or more resource IDs (space-delimited). It should be a complete resource ID
containing all information of 'Resource Id' arguments. You should provide
either --ids or other 'Resource Id' arguments.
• --name
-n Name of the CDN endpoint.
• --no-wait
Do not wait for the long-running operation to finish.
• --profile-name
Name of the CDN profile which is unique within the resource group.
• --resource-group
-g Name of resource group. You can configure the default group using az
configure --defaults group=.
• --subscription
Name or ID of subscription. You can configure the default subscription using az
account set -s NAME_OR_ID.****
Azure Devops Task for Purge CDN
Below
is the task which we can use inside the Azure Devops Pipeline to execute the
purge command in Azure CDN to clear and update the cache in CDN servers.
We
are giving --no-wait so that we don't wait till the CDN is
getting purged. If we don't have this parameter flag set, then this task will
wait till the CDN content is purged fully.
- task: AzureCLI@2
displayName: "Azure CLI: Purge
CDN"
inputs:
azureSubscription:
$(azureSubscription)
scriptType: "ps"
scriptLocation: inlineScript
inlineScript: |
az cdn endpoint purge -g
$(azureResourceGroupStorageAccount) --profile-name $(cdnProfileName) --name
$(cdnEndPoint) --no-wait --content-paths "/path-of-folder-to-purge/*"
Reference:
https://docs.microsoft.com/en-us/cli/azure/cdn/endpoint?view=azure-cli-latest#az_cdn_endpoint_purge