Cache Purging in Azure Front Door Using Azure CLI
Azure Front Door caches assets until their time-to-live (TTL) expires. When a client requests an asset with an expired TTL, Azure Front Door retrieves a new copy of the asset, serves the request, and updates the cache.
To ensure users always get the latest assets, version your assets for each update and publish them with new URLs. Azure Front Door fetches the new assets for subsequent client requests. Sometimes, you might need to purge cached content from all edge nodes to force them to retrieve updated assets. This action is useful when updates are made to your application or need to correct incorrect information.
Prerequisites
Use the Bash environment in Azure Cloud Shell. For more information, see Quickstart for Bash in Azure Cloud Shell.
If you prefer to run CLI reference commands locally, install the Azure CLI. If you're running on Windows or macOS, consider running Azure CLI in a Docker container. For more information, see How to run the Azure CLI in a Docker container.
If you're using a local installation, sign in to the Azure CLI by using the az login command. To finish the authentication process, follow the steps displayed in your terminal. For other sign-in options, see Sign in with the Azure CLI.
When you're prompted, install the Azure CLI extension on first use. For more information about extensions, see Use extensions with the Azure CLI.
Run az version to find the version and dependent libraries that are installed. To upgrade to the latest version, run az upgrade.
- Review Caching with Azure Front Door to understand how caching works.
- Ensure you have a functioning Azure Front Door profile. Refer to Create an Azure Front Door - CLI to learn how to create one.
Configure Cache Purge
Run az afd endpoint purge with the necessary parameters:
- Resource group name
- Azure Front Door profile name within the resource group
- Endpoints with assets to purge
- Domains/Subdomains with assets to purge
Important
Cache purge for wildcard domains is not supported. Specify a subdomain for cache purge for a wildcard domain. You can add multiple single-level subdomains of the wildcard domain. For example, for the wildcard domain *.afdxgatest.azfdtest.xyz
, you can add subdomains like contoso.afdxgatest.azfdtest.xyz
or cart.afdxgatest.azfdtest.xyz
. For more information, see Wildcard domains in Azure Front Door.
- Path to the content to be purged:
- Supported formats:
- Single path purge: Specify the full path of the asset (without the protocol and domain), including the file extension, for example, /pictures/strasbourg.png.
- Root domain purge: Purge the root of the endpoint with "/*" in the path.
- Supported formats:
az afd endpoint purge \
--resource-group myRGFD \
--profile-name contosoafd \
--endpoint-name myendpoint \
--domains www.contoso.com \
--content-paths '/scripts/*'
Cache purges on the Azure Front Door profile are case-insensitive and query string agnostic, meaning to purge a URL purges all its query-string variations.
Note
Cache purging can take up to 10 minutes to propagate throughout the network and across all edge locations.
Next steps
To continue, learn how to create an Azure Front Door profile.