Adding Cache-control to content on Azure Blob storage
All CDN service have the ability to respect whichever cache control directives the origin server sends.
Some even require the origin to provide caching headers, as they don't have the capability to set caching policy at the edge.
Azure Blob Storage can be set up as an origin that supplies cache-control headers, by using 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.
The following are examples of cache-control headers.
Cache on the edge for 10 days, and on the browser for 2 hours
Cache-Control "public, max-age=14400, s-maxage=8640000"Do not cache
Cache-Control "private, no-cache"This code example will set up a Blob objects to use cache-control.
The code has been taken from this MSDN articleHow to Manage Expiration of Blob Content in the Azure Content Delivery Network (CDN)
using System; using Microsoft.WindowsAzure; using Microsoft.WindowsAzure.StorageClient; namespace BlobsInCDN { class Program { static void Main(string[] args) { //Specify storage credentials. StorageCredentialsAccountAndKey credentials = new StorageCredentialsAccountAndKey("storagesample", "m4AHAkXjfhlt2rE2BN/hcUR4U2lkGdCmj2/1ISutZKl+OqlrZN98Mhzq/U2AHYJT992tLmrkFW+mQgw9loIVCg=="); //Create a reference to your storage account, passing in your credentials. CloudStorageAccount storageAccount = new CloudStorageAccount(credentials, true); //Create a new client object, which will provide access to Blob service resources. CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient(); //Create a new container. CloudBlobContainer container = blobClient.GetContainerReference("cdncontent"); container.CreateIfNotExist(); //Specify that the container is publicly accessible. BlobContainerPermissions containerAccess = new BlobContainerPermissions(); containerAccess.PublicAccess = BlobContainerPublicAccessType.Container; container.SetPermissions(containerAccess); //Create a new blob and write some text to it. CloudBlob blob = blobClient.GetBlobReference("cdncontent/testblob.txt"); blob.UploadText("This is a test blob."); //Set the Cache-Control header on the blob to specify your desired refresh interval. blob.SetCacheControl("public, max-age=31536000"); } } public static class BlobExtensions { //A convenience method to set the Cache-Control header. public static void SetCacheControl(this CloudBlob blob, string value) { blob.Properties.CacheControl = value; blob.SetProperties(); } } }