Blog Programming Tips Azure Infrastructure

In a previous post I wrote about a couple of problems I have with Azure, the main one being the lack of a purge function on the CDN. 

 I want the ability to crop, resize and upload multiple times for the same filename, the lack of a purge function makes it pretty difficult

For a while I have been just using Azure storage to serve and host my images, I recently watched a video that shows how wasteful this could be, and how my speed could dramatically improve if I used the CDN.

I first enabled query strings on my azure CDN.


When I wrote the uploader I did not add any sort of cache header to the files, this meant that the default was attached. I believe this is 72 hours. I lowered the image default all the way down to 10 minutes.

I then added a version column to my images table in the database


, along with my repositories, mappings and models:


I then added a boolean property onto the form model. This was defaulted to false, when true it will generate a new verion


This was then added into the front end in my edit partial.


I used the same method when cropping any new images


Finally I amended my image CDN URL helper methods to add in the version number into the query string.


I also had my CDN URL pointing at storage, my last change was the change this back to (which points to ) and I was done.


I now have a unique image URL when a version exists and when I am using the CDN, I thought about having the version as a incrementing number, but I didn’t really see the point, I don’t need to know the history of the file in the URL. I may replace this with something other than a Guid, but for now it works just fine and ensures it is always unique when an image is re-cropped/ uploaded 


A pretty simple workaround for the missing feature.