As all developers know our best friend and worst enemy is the cache. You can make all your changes and be confident they will work, then they don’t change just when you want them to. It is great that you can clear your own cache, but how can you refresh all the users cache? Here are some of the methods I know of and used.
First up is the query string method. When the browser caches the file it caches the URL for it location. This included the query string of the URL. It makes it like the key to the value, so if you change the key then it needs to get a new value.
The query string can be anything, so you could even just put the number.
You can then make this dynamic my appending the build number of your deployment. This however is dependent on who, what and where your file is. Unfortunately as well, some browsers don’t use the whole URL. They cut the Query string off for the Key part of the cache. This means this method doesn’t work for some browsers.
IIS URL Rewrite
This can be done in IIS and also using the .htaccess on an apache server. For this you will need to install the IIS URL Rewrite tool from Microsoft.
The use of this is to rewrite the directory of the URL instead, so unlike the previous method it would work in every browser. The only issue I have found with this is I don’t know how to add a version number on there without having to physically add a number on the end for each deployment. You can however also use this in the web.config of the application, where you might be able to dynamically get the number of the build.
Here is how to use the URL Rewriter:
Restart Application Pool
If you are ok with this then you could also script a PowerShell script to restart the applications at will. This can be done with dunning iisreset from an elevated (on Vista/Win7/Win2008) command prompt, which will restart IIS and in turn restart all the application pools.
These are just some method that can used and there are also other way to use the premises, but in maybe better ways for your application. If you have any other methods please comment them below and share the knowledge.