Cache purging in Azure Front Door with Azure CLI
Azure Front Door caches assets until the asset's time-to-live (TTL) expires. Whenever a client requests an asset with expired TTL, the Azure Front Door environment retrieves a new updated copy of the asset to serve the request and then stores the refreshed cache.
Best practice is to make sure your users always obtain the latest copy of your assets. The way to do that is to version your assets for each update and publish them as new URLs. Azure Front Door Standard/Premium will immediately retrieve the new assets for the next client requests. Sometimes you may wish to purge cached contents from all edge nodes and force them all to retrieve new updated assets. The reason you want to purge cached contents is because you've made new updates to your application, or you want to update assets that contain 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.
- Have a functioning Azure Front Door profile. Refer to Create a Front Door - CLI to learn how to create one.
Configure cache purge
Run az afd endpoint purge to purge cache after inputting the necessary parameters like:
Name of resource group
Name of the Azure Front Door profile within the resource group with assets you want to purge
Endpoints with assets you want to purge
Domains/Subdomains with assets you want to purge
Important
Cache purge for wildcard domains is not supported, you have to specify a subdomain for cache purge for a wildcard domain. You can add as many single-level subdomains of the wildcard domain. For example, for the wildcard domain
*.afdxgatest.azfdtest.xyz
, you can add subdomains in the form ofcontoso.afdxgatest.azfdtest.xyz
orcart.afdxgatest.azfdtest.xyz
and so on. For more information, see Wildcard domains in Azure Front Door.The path to the content to be purged.
- These formats are supported in the lists of paths to purge:
- Single path purge: Purge individual assets by specifying the full path of the asset (without the protocol and domain), with the file extension, for example, /pictures/strasbourg.png.
- Root domain purge: Purge the root of the endpoint with "/*" in the path.
- These formats are supported in the lists of paths to purge:
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. Additionally, they're query string agnostic, which means to purge a URL will purge all query-string variations of it.
Note
Cache purging can takes up to 10 mins to propagate throughout the network and across all edge locations.
Next steps
Learn how to create an Azure Front Door profile.