Under unusual circumstances ColdFusion MX 7 server may cache a File Not Found (404 Status Code) error for a template and continue to return the error even when the expected template file resides in the proper location.

For a short reproducible case, create page hello.cfm with the text Hello and browse it. You'll see the page successfully completes. Rename the file to anything else, perhaps hello2.cfm, and browse to the original page hello.cfm again. Assuming that the CF Administrator setting for Missing Template Handler is not configured, you will receive a File Not Found error like this:

view plain print about
1File not found: /hello.cfm
2 ...<br/><br/>coldfusion.runtime.TemplateNotFoundException: File not found: /hello.cfm
3    at coldfusion.filter.PathFilter.invoke(PathFilter.java:83)
4    at coldfusion.filter.ExceptionFilter.invoke(ExceptionFilter.java:69)
5    at coldfusion.filter.BrowserDebugFilter.invoke(BrowserDebugFilter.java:52)
6    ...


At this point, the ColdFusion server is doing the right thing. Now to demonstrate the improper caching of the File Not Found error message, rename the hello2.cfm file back to the original file name hello.cfm. When you browse the hello.cfm file again, you will continue to see the error message even though the file is in the correct location with the original name.

This behavior will occur even when the settings Trusted Cache and Save Cache Files are turned off.

To workaround the problem in ColdFusion MX 7, create a template that uses the Admin API to clear the Template Cache. The method is called clearTrustedCache(), but this is just a slight misnomer as the Template Cache is cleared. Then configure this template as the Missing Template Handler in the ColdFusion Administrator Settings page. For usefulness, provide the name of the missing file and a link to try the page again, and add any other handling behavior you think might be pretty or appropriate.

An example of what the Missing Template Handler might look like is the following:
view plain print about
1[cflock name="clearTrustedCacheLock" type="EXCLUSIVE" timeout="5" throwontimeout="No">
2    [cfscript>
3        request.CFADMIN_PASSWORD = "admin";
4        request.adminObj = createObject("Component", "cfide.adminapi.administrator");
5        request.adminObj.login(request.CFADMIN_PASSWORD);
6        request.runtimeObj = createObject("component", "cfide.adminapi.runtime");
7        request.runtimeObj.clearTrustedCache();
8    [/cfscript>
9[/cflock>
10
11[cfoutput>
12#error.message#<br/>
13<a href="#cgi.script_name#">Try again</a>
14[/cfoutput>