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

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.
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.