Tip of the week: Clean those ASP.NET temp files

Note: this post is over a year old, it's very likely completely outdated and should probably not be used as reference any more. You have been warned. :-)

One of the things that Umbraco 5 plugin developers have been struggling with from day 1 is ASP.NET aggressive caching of their assemblies. As it appears, after you build your plugin code and put the new dll into the plugins folder, many times the new code will not be used. Instead, you get the stale cached version and that's very unproductive.

Shannon did a lot of great research last month focussing on just this problem and I'm happy to see that these problems might become obsolete in one of the upcoming versions of Umbraco 5.

From what I've distilled from his blogpost though, there's a very easy way to forces ASP.NET to clear the cache: touch the global.asax instead of the web.config. 

One thing that has bothered me for YEARS now is that I have to go into the web.config, add a space, save, etc. Today I realized that it would be so easy to automate this.

A quick search return a tiny utility called FileTouch that does what it says on the tin: change the modify date (or create date, or access date) of a file.

So I made a tiny little batch file that does just that for me: 

FileTouch .\Umbraco.Web\Global.asax

That's all! I found the temp folder of the site I'm currently working on, executed the above command line and once I try to access the site again I see everything disappearing from the ASP.NET temp folder quickly and new files being put in that equally fast.

You could also make this an afterbuild event in your project but I don't always want the extra hit (rebuilding the cache takes a little extra time), so I prefer to just have the command line open and executing the batch file whenever I think I'll need it.

Foto courtesy of: http://www.flickr.com/photos/emilyrides/5188289325/

Sebastiaan Janssen

Dutch guy living in (and loving) Copenhagen, working at Umbraco HQ. Lifehacker, skeptic, music lover, cyclist, developer.


3 comments on this article

Avatar for Andy Butland Andy Butland | April 13 2012 15:24
Looks handy... have you had chance to see if this technique works with embedded views too? Have had trouble with getting those to update when working on plug-ins using them.

Avatar for Sebastiaan Janssen Sebastiaan Janssen | April 13 2012 17:16
Yup, that was exactly what I was having trouble with as well. So far so good, no more stale embedded views. :-)

Avatar for Petr Šnobelt Petr Šnobelt | April 28 2012 00:20
Thank you for sharing usefull information.