Paradise
Paradise

Reputation: 81

Update file in Windows Azure CDN

I have blob storage and CDN endpoint, that store my static content. Now I want to update app.js file, because it was modified, but when I write this file to blob, CDN still gives me old app.js file. How can I update my app.js file? Or I have to wait until my cache is not going to end?

Upvotes: 7

Views: 4846

Answers (6)

PRASHANT SALVI
PRASHANT SALVI

Reputation: 11

You can purge the content from Azure new Management portal.

Upvotes: 0

Chintan Shah
Chintan Shah

Reputation: 3673

Question was asked quite long ago. I just wanted to update on method that proved useful for me. Its recommended by Microsoft. Essentially you need to set up cache-control headers in your Blob Storage. You can set cache control header with value "public, max-age=3600". This will cache your file for about 1 hour.

https://azure.microsoft.com/en-us/documentation/articles/cdn-manage-expiration-of-blob-content/

Upvotes: 2

Ben Edwards
Ben Edwards

Reputation: 1

The only way to do this right this now is to contact Azure Support and they will in turn open a support ticket with Verizon EdgeCast to remove the file from the CDN and it will update at that point. This whole process takes about 8 hours on the basic Azure support plan. This isn't a good solution and I really hope they update this to where we can programmatically purge something from the CDN. This seems like a basic feature they are lacking. Your best bet I think right now is to enable querystring status and then update that querystring when you update. We do this for js files like so /js/custommix.js?version=1. Then we append a new version from our config when we need to update those.

http://azure.microsoft.com/en-us/blog/best-practices-for-the-windows-azure-content-delivery-network/

How can I purge or invalidate content in the Windows Azure CDN?

As of 1.4, no purge function is available. This feature is under development. The best freshness control is to set good cache expiration headers as described in this document and the Windows Azure CDN documentation on MSDN.

Upvotes: 0

Masood Khaari
Masood Khaari

Reputation: 3061

Simply you can't update the cache object before its expiration.

From https://msdn.microsoft.com/en-us/library/azure/gg680303.aspx:

If you no longer wish to cache an object in the Azure Content Delivery Network (CDN), you can take one of the following steps:

  • For a Azure blob, you can delete the blob from the public container.

  • You can make the container private instead of public. See Restrict Access to Containers and Blobs for more information.

  • You can disable or delete the CDN endpoint using the Azure Management Portal.

  • You can modify your hosted service to no longer respond to requests for the object.

An object already cached in the CDN will remain cached until the time-to-live period for the object expires. When the time-to-live period expires, the CDN will check to see whether the CDN endpoint is still valid and the object still anonymously accessible. If it is not, then the object will no longer be cached.

No explicit "purge" tool is currently available for the Azure CDN.


Other workarounds include using either fake query strings or new file names, if possible. See here: https://stackoverflow.com/a/8773202/908336

Upvotes: 2

Craig H
Craig H

Reputation: 2071

It appears the default expiration time is 7 days.

From: http://msdn.microsoft.com/en-us/library/azure/gg680306.aspx

Blobs that benefit the most from Azure CDN caching are those that are accessed frequently during their time-to-live (TTL) period. A blob stays in the cache for the TTL period and then is refreshed by the blob service after that time is elapsed. Then the process repeats.

You have two options for controlling the TTL:

  1. Do not set cache values thus using the default TTL of 7 days.

  2. Explicitly set the x-ms-blob-cache-control property on a Put Blob, Put Block List, or Set Blob Properties request, or use the Azure Managed Library to set the BlobProperties.CacheControl property. Setting this property sets the value of the Cache-Control header for the blob. The value of the header or property should specify the appropriate value in seconds. For example, to set the maximum caching period to one year, you can specify the request header as x-ms-blob-cache-control: public, max-age=31556926. For details on setting caching headers, see the HTTP/1.1 specification.

Upvotes: -1

user94559
user94559

Reputation: 60143

The CDN is simple. When a request comes in, it fetches the content from the origin (in this case, blob storage), and then caches it for some time based on the Cache-Control header. It will keep delivering the same content until the cache expires.

There's no way to tell the CDN to expire something early.

Others may jump in with more helpful advice about how to deal with this (like query string parameters), but I just wanted to give a straightforward explanation of how the CDN's caching works.

Upvotes: 1

Related Questions