Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 276
Paradise Avatar asked Sep 21 '12 10:09

Paradise


3 Answers

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

like image 68
Masood Khaari Avatar answered Dec 19 '22 17:12

Masood Khaari


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/

like image 26
Chintan Shah Avatar answered Dec 19 '22 17:12

Chintan Shah


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.

like image 41
user94559 Avatar answered Dec 19 '22 17:12

user94559