How do I force Azure CDN content to be purged or invalidated?

I have content that rarely changes that I want to serve over the Azure CDN for performance reasons. When the content does change, though, it's important that the updated data is immediately available. Ideally, I'd be able to set a long TTL but then proactively tell the CDN to expire content when I update it. How can I accomplish this? There is no cache invalidation or purge API right now, and I would rather not set a short TTL.


In 2015 December the Azure team added the ability to refresh or purge the CDN via REST API (https://msdn.microsoft.com/en-us/library/mt634451.aspx). In the beginning, this function is only available for endpoints created with the new Azure Portal (http://portal.azure.com), however, CDNs created with the old management surface will be migrated in the beginning of 2016 (https://feedback.azure.com/forums/169397-cdn/suggestions/556307-ability-to-force-the-cdn-to-refresh-any-cached-con).


There is NO API to invalidate an Azure CDN.

Workaround:

  • Enable "Query String Status" on your CDN in Azure portal. Then you can append a new query string name and random value eg. /images/background.png?v=1234

  • Upload and rename the new file with a timestamp or random value. for example: /images/background.20140917225200.png

  • Set a shorter cache header and wait for it to expire. Here's an article from the Azure team http://msdn.microsoft.com/en-us/library/azure/gg680306.aspx


  • You cannot force CDN purge.

    Best practice is to append version/date info to your file name, and design your app to dynamically get the current file name.

    For product photos as an example, append the version to the blob name, store the blob name in a table, and then serve a link to the name from the table, instead of hard-coding the filename.

    This way you can set max-expiry on the cache headers, and Azure will just clean up stale content when it needs to.

    链接地址: http://www.djcxy.com/p/65542.html

    上一篇: 304在Azure Blob存储中托管的Azure CDN图像的状态代码

    下一篇: 我如何强制清除Azure CDN内容或使其失效?