Force ColdFusion Server To Recompile A ColdFusion Template

Posted May 2, 2007 at 7:04 PM by Ben Nadel

Tags: ColdFusion

Have you ever made changes to a ColdFusion page and uploaded it only to be disappointed that your changes have not taken place. For some reason, sometimes ColdFusion does not acknowledge that the file has changed. There are probably caching settings that you can set so that this does not happen... but I don't know what those are and I'm rarely in the ColdFusion admin.

So, how do I deal with this? I put a few dozen line breaks at the end of the file and re-upload. The line breaks do not change the file in any functional way (and if they do, put them inside of ColdFusion comment tags), but this will create enough of a file size change for ColdFusion to finally take notice of the update. Once noticed, ColdFusion will recompile and serve you the new page. At this point, you can remove the spaces and re-upload (and who cares how long it take ColdFusion to recompile that version - no functional change).

This is a bit of hack, but if you didn't know this was an option, it might save you a few head-banging sessions. And, I'm not talking about needing this for every file; if you need to do this all the time, looking into other solutions. This is for that very rare situation where ColdFusion just wants to ignore your changes.



Reader Comments

May 2, 2007 at 8:01 PM // reply »
7 Comments

Another thing that usually works is do a touch on the file, it'll update the timestamp on the file and trick CF into thinking that it changed. That's a good first step as it doesn't require altering and republishing code.


May 2, 2007 at 8:22 PM // reply »
5 Comments

Chances are its not coldfusion that is not recompiling, it is probably the webserver itself (apache, iis, etc). If the filesize doesn't change, sometimes it wont pull the file again.

One time, I was even getting a 404 not found error on a file that I knew existed and I was beating my head on the wall trying to figure out what was happening. Turns out, the file was 404kb in size! as soon as I took out some extra whitespace and made it 403 it actually started workng again.


May 2, 2007 at 8:50 PM // reply »
48 Comments

Sounds like trusted cache is turned on. It's very easy to flush this cache via the admin - I'd rather do that then hack around with the template itself.

You really should get to know and love your CF administrator.


May 2, 2007 at 11:08 PM // reply »
6 Comments

@Todd - unfortunately, when on shared hosting, its just not an option.


May 3, 2007 at 7:13 AM // reply »
11,238 Comments

@Tariq,

Touching a file sounds good. I know the idea behind it, but how does one accomplish this? I develop on a Windows machine (if that helps). Does this make a difference if the "Date Modified" has already been changed? I guess the question is, what does touching it do... (Police: CFM, can you show us on the doll where he Touched you?)

@Ryan,

I am not sure I follow this; Are you saying that IIS is caching files (forgive me, I know zero about server stuff)? I thought IIS just saw that it was a CFM request and immediately hands it off to the ColdFusion App Server?

Yeah, I have also gotten 404 errors on files that exist! So frustrating. That's a huge file you were working with. I assume it wasn't a CF file as don't they have like a 63K max size limit?

@Todd,

Can you give me the 2 second run down on Trusted Cache? Does that get turned on/off for a site-specific basis or for all CF apps on the server? What are the implications.


May 3, 2007 at 8:48 AM // reply »
43 Comments

Trusted cache is simply a setting that tells the CF server that, if the template is cached, to use the cached version. Period. Otherwise, the timestamp (and maybe other properties?) are checked to determine whether to serve the cached version or recompile. It's a useful setting in production. A really annoying setting in dev environments. :-)

The setting applies to all applications running on that particular CF server.


May 3, 2007 at 9:21 AM // reply »
4 Comments

Have you tried changing the headers? For example:

<cfset today = createDate(year(now()), month(now()), day(now()))>
<cfset yesterday = dateAdd("d", -1, today)>
<cfheader name="Expires" value="#GetHttpTimeString(yesterday)#">


May 3, 2007 at 9:45 AM // reply »
6 Comments

@Ben - I'm pretty sure that the Trusted Cache option is server-wide. Personally, I've never enabled it... never had any sites that I didn't envision making updates to at some point.


May 3, 2007 at 9:50 AM // reply »
20 Comments

From the CFAdministrator, under "Server Settings -->Caching"

"Trusted cache
When checked, any requested files found to currently reside in the template cache will not be inspected for potential updates. For sites where templates are not updated during the life of the server, this minimizes file system overhead. This setting does not require restarting the server."

"Save class files
When you select this option, the class files generated by ColdFusion are saved to disk for reuse after the server restarts. Macromedia recommends this for production systems. During development, Macromedia recommends that you do not select this option."

However, I've also had problems with browsers' stubborn refusal to stop caching web pages, despite me telling them not to.


May 3, 2007 at 1:52 PM // reply »
7 Comments

@Ben: ya touch comes from the unix world, but I'm a Windows guy myself. There's a couple of ports of touch, basically alters created and last modified time stamps

http://www.codeproject.com/tools/touch_win.asp
http://www.gregorybraun.com/FMXTouch.html

I should do a blog posting for Windows CF'ers on the unix shell for Windows called Cygwin. It's like a self contained unix dos prompt that lets you plugin all the common tools from the unix world.

Handy for when you need to do stuff that can't really be done easily in Windows out of the box.

E.g, what if you wanted to find out how many lines of code your CF files have. You could do a:

find . -name "*.cf?" | xargs cat | wc -l


May 3, 2007 at 8:16 PM // reply »
11,238 Comments

Thanks for the info on Trusted Cache, guys. The only concern (not really a concern) is that this is a production server - are there issues with turning this on and off in terms of drain on the server (I assume not).

But really, and this might just be me, going into the Admin, and turning off the trusted cache, seems like the same amount of work as adding lots of white space to a file. Just personal... but good to know all the options.

As far as this Touch issue... not sure if that is what it is. When things like this happen, the local date modified stamp will update. But, it seems that when the file is uploaded, this timestamp change is either not carried over to the new server or is ignored.

Just a thought - if the two servers have different clocks (times zones), do the date modified times stamps update automatically?


May 4, 2007 at 3:19 AM // reply »
19 Comments

Trusted Cache is quite useful, and contrary to Max said enabling it doesn't mean you can't disable it later to upload a change or just clear the template cache and leave it on.

For instance it can give you a pretty substantial speed boost for complicated execution paths or framework heavy code like CS+MG+Reactor.

It's also a very important if you're pushing a large set of changes to the server. Conventionally, if you push individual files to the server it's possible that a client could get the application in an inconsistent state where one part of it was uploaded, but the other part hadn't finished yet. The more code the more likely this becomes.

One solution to this problem is to upload the files in a separate location on the server and do an atomic swap of the entire application directory. An alternative solution is to use the trusted cache and push the files to the server, then clear the template cache. This makes pushing delta changes to the server nicer too.

I can't say I've ever seen a noticeable performance hit from doing this either. I suppose the next person who requests the page is going to get a slower response, but following responses would be just as fast as before. Considering you don't have trusted cache enabled at all right now, that won't be an issue anyway.

(On a side note: Adding whitespace to a file will not work around the trusted cache. When trusted cache is enabled the server ignores the code on disk that was already loaded.)


May 4, 2007 at 7:03 AM // reply »
11,238 Comments

If white space changes are ignored when Trusted Cache is turned on, then that must mean that it is not turn on on one of our production servers? Otherwise that hack, as you say, would not have any effect.

If that is the case, any ideas where the cache is coming from? Is this a date/time modified issue at that point?


mik
Oct 1, 2007 at 3:29 PM // reply »
1 Comments

The only Solution that I found was to delete the files in the Folder CFusionMX7\wwwroot\WEB-INF\cfclasses, after that everything worked perfect again


May 16, 2008 at 9:47 PM // reply »
1 Comments

I just discovered that turning off Save class files in the ColdFusion Administrator gets rid off the Page not found errors that erroneously pop up when the page in fact does exist. I am not sure why and any assistance from someone more knowledgeable would be appreciated. =)


Tim
Jun 26, 2008 at 4:58 PM // reply »
10 Comments

Another twist on this old thread.... from time to time, we *delete* a .cfm file and since the .class file still exists (we have "save class files" on), it still tries to serve it up. That is the only way I can explain it -- the file is not there, but code in it (when it was there) executes.

I cleared all the .class files (ouch... production server) and that seems to have solved the issue.

Anyone else seen that?

Tim


Sep 2, 2010 at 11:13 AM // reply »
1 Comments

@M. Williams,

it is an old post but as you said unchecking Save class file helped me for the 404 error, thanks.

Emidio


Apr 21, 2012 at 1:12 PM // reply »
8 Comments

Adding a chunk of code really is a life saver, when trying to get rid of cached templates. Thx for the hack!



Post A Comment

Comment Etiquette: Please do not post spam. Please keep the comments on-topic. Please do not post unrelated questions or large chunks of code. And, above all, please be nice to each other - we're trying to have a good conversation here.

Please review the following issues:

Author Name:


Author Email:

Author Website:

Comment:

Supported HTML tags for formatting: <strong>bold</strong>   <em>italic</em>   <code>code</code>







  • Help Wanted - Find Your Next ColdFusion Job
Ben Nadel's Company - Epicenter Consulting Recent Blog Comments
May 22, 2013 at 4:43 AM
How Do You Use The ColdFusion CFParam Tag?
'<cfparam>' or 'isDefined()and <cfset>' performs the same task.Is there any difference? ... read »
May 21, 2013 at 7:46 PM
Using Plupload For Drag & Drop File Uploads In ColdFusion
No luck. At least I have uncovered the cause, URLScan 3.1. Here is what I see in the IIS log when a file is over 30mb. 2013-05-21 23:29:05 10.105.45.128 GET /plupload/assets/jquery/jquery-1.8. ... read »
May 21, 2013 at 6:12 PM
Using Plupload For Drag & Drop File Uploads In ColdFusion
Ben, I did not see you after Pete Freitag's Lockdown session at cfObjective but he said that IIS sets file size limits at 30MB by default which just happened to be the threshold for file size when ... read »
May 21, 2013 at 11:51 AM
Ask Ben: Parsing Very Large XML Documents In ColdFusion
Looking at my first ever XML document that I have to parse and put into MS SQL 2000 with CF8. I get it to list the desired Field name, many times over, and have a long list of this field name displa ... read »
May 21, 2013 at 9:25 AM
Turning Off and On Identity Column in SQL Server
you are awesome..i am lucky to get this blog between such a garbage one....Thanks, Prashant ... read »
May 20, 2013 at 4:38 PM
Using A Dynamic Column Name With ValueList() In ColdFusion
@Dana, Your confusion is well founded, since this is a very confusing features. In fact, it ONLY works if you use array notation. Meaning, that this: arrayToList( query[ "columnName" ] ) ... read »
May 20, 2013 at 4:34 PM
Using A Dynamic Column Name With ValueList() In ColdFusion
I was thinking chicken and the egg, I wouldn't have expected it to work in the valuelist going in I guess. Maybe I just need a beer, long day :) ... read »
May 20, 2013 at 4:29 PM
Using A Dynamic Column Name With ValueList() In ColdFusion
@Dana, That's if you're trying to reference a specific row. In this case, we're trying to reference the entire query column as one cohesive value. So, you are correct that if you wanted to output a ... read »
InVision App - Prototyping Made Beautiful With Prototyping Tools