I'm using Azure Storage to serve up static file blobs but I'd like to add a Cache-Control and Expires header to the files/blobs when served up to reduce bandwidth costs.
Application like CloudXplorer and Cerebrata's Cloud Storage Studio give options to set metadata properties on containers and blobs but get upset when trying to add Cache-Control.
Anyone know if it's possible to set these headers for files?
Append Blob is specifically optimized for operations where we need to keep adding data to a blob in chunks without modifying the already existing content. Every newly added data appends to the end of the blob, operation being referred as appending.
I had to run a batch job on about 600k blobs and found 2 things that really helped:
Running the operation in parallel. The Task Parallel Library (TPL) in .net v4 makes this really easy. Here is the code to set the cache-control header for every blob in a container in parallel:
// get the info for every blob in the container var blobInfos = cloudBlobContainer.ListBlobs( new BlobRequestOptions() { UseFlatBlobListing = true }); Parallel.ForEach(blobInfos, (blobInfo) => { // get the blob properties CloudBlob blob = container.GetBlobReference(blobInfo.Uri.ToString()); blob.FetchAttributes(); // set cache-control header if necessary if (blob.Properties.CacheControl != YOUR_CACHE_CONTROL_HEADER) { blob.Properties.CacheControl = YOUR_CACHE_CONTROL_HEADER; blob.SetProperties(); } });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With