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:

ColdFISH is developed by Jason Delmore. Source code and license information available at coldfish.riaforge.orgFile not found: /hello.cfm ...<br/><br/>coldfusion.runtime.TemplateNotFoundException: File not found: /hello.cfm at coldfusion.filter.PathFilter.invoke(PathFilter.java:83) at coldfusion.filter.ExceptionFilter.invoke(ExceptionFilter.java:69) at coldfusion.filter.BrowserDebugFilter.invoke(BrowserDebugFilter.java:52) ...1File not found: /hello.cfm2 ...<br/><br/>coldfusion.runtime.TemplateNotFoundException: File not found: /hello.cfm3 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:

Comments (Comment Moderation is enabled. Your comment will not appear until approved.)

One real world scenario where the cached 404 File Not Found message continues to be served is when serving content from a UNC share an interruption occurs on the network. When CF can`t access the remote file it reports a 404, and when the content is available CF will continue serving the 404 unless this blog entry`s workaround is used.

The Trusted Cache setting just says weather or not to trust what is in the Template Cache. In this context, there is only one cache being referenced. The Trusted Cache setting would be better named something like "Trust the Template Cache", and maybe it would be clearer.

The server setting for trusted cache simply tells the server to either always check to see if the timestamp of every template has changed or to never check the the timestamps. If the setting is enabled, ColdFusion never checks the timestamps and it accepts that the templates it has in memory (in cache) are to be used to handle requests.

The template cache setting is how many cfm/cfc templates are held in memory and guaranteed to not be garbage collected (using a Last Recently Used, LRU, caching model to bump old templates out when the cache is full and new templates try to get in).

The problem in this File Not Found issue described here is that timestamp on the file never changes, although for a moment the file wasn`t available and the generated HTML corresponding to the 404 error was put in memory. When the file is available again, ColdFusion sees that the timestamp *still has not* changed, so ColdFusion never re-reads the template file and just keeps serving the cached 404 message.

Since in the example the timestamps on the cfm files never change, the Trusted Cache setting has no relevance and the server executes the template version it has in memory in theTemplate Cache.

Thanks for the explanation. I was thinking TrustedCache might be a setting and not a separate entity. And I see how this caching issue is really an artifact of doing a rename/rename on the file.

Interestingly, though, this happens even when the `Maximum number of cached templates` is set to zero. (CFMX v7.0.1 CHF2 on Solaris 9). I would have thought setting that to zero would force no caching.

I`m having this same issue. I`ve tried clearing the Template Cache through the administrator with no success. I also tried using the sample Missing Template Handler - but when I specify that page as the handler through the CF Administrator, it doesn`t seem to do anything and if I go directly to that page I get the error below. However, I`m not familiar with the Admin API...

Error from accessing the Missing Template Handler directly: The string "COOKIE.CFAUTHORIZATION_meded-db" is not a valid ColdFusion variable name.Valid variable names must start with a letter, and can only contain letter, numbers, and underscores.

The error occurred in C:lackstone_updatescfusionwwwrootCFIDEadminapiadministrator.cfc: line 106

How would I go by setting up a Missing Template Handler on a CF MX7 server where I am set up as a seperate instance with my own admin console. I dont have access to the C: of the servers, or would I have to get the admins to add the Missing Template Handler cfm file on the C: drive?

There`s not enough information to understand your inquiry. It sound as though you have an extra ColdFusion instance devoted for your usage and that you do not have access to the C: drive. Having access to C: drive root doesn`t matter, but I assume that you must have write permission to the document root. Create a template there and then simply configure it as the missing template handler in the CFAdmin. I assume that if you have your own instance that you have access to the CFAdmin for that instance. On the CFAdmin "Server Settings" page, read the instructions below the field for Missing Template Handler, and you could find more help by clicking on the ? icon in the upper right.

I`m having a problem that seems to be the same; however, this script doesn`t solve the problem. I had a Oracle stored procedure changed and it was temporarily in a state of `invalid` when it was referenced through the site. After having him get back and fix it and getting it to the `compiled` state, CFMX never rechecked the stored procedure, just simply posted back the original error message.

While this sounds more like a flaw in the design, there must be some way, other than restarting the service, to clear this error cache? Maybe a way to restart the JDBC? I don`t know.

I`m having a problem that seems to be the same; however, this script doesn`t solve the problem. I had a Oracle stored procedure changed and it was temporarily in a state of `invalid` when it was referenced through the site. After having him get back and fix it and getting it to the `compiled` state, CFMX never rechecked the stored procedure, just simply posted back the original error message.

While this sounds more like a flaw in the design, there must be some way, other than restarting the service, to clear this error cache? Maybe a way to restart the JDBC? I don`t know.

Adobe have said this is not a bug that they have been able to replicate themselves, so no bug fix is on the cards. Is there a specific set up or configuration that we`re all using that causes this "bug" to appear?

I`m using a 2-server IIS cluster (NLB, sticky session) with templates stored on a file server (on a 3rd machine).

Steven, we have a mix of cfm and html files and have never experienced a 404 with static html files. CF is running under a domain account and has full read/write access to the entire directory structure. The "clear template cache" button temporarily fixes the 404 when we get them... until another cfm file suddenly reports a 404. We have 2 servers in a cluster and when one gets a 404 on a specific file the other server will happily serve the "missing" file correctly.

As you stated earlier, re-saving a file to update the timestamp also fixes the problem for the file in question.

What we can`t detect is what the problem was at the time CF/JRun thought there was a network/file error. We haven`t experienced other apps/services or Windows in general suggesting there is a file problem. Will the fix be part of 7.0.2? Thanks.

We are battling with this same issue, currently. Opening a file and resaving always fixes the issue. However, we are running on CFMX 6.1 and apparently the Component cfide.adminapi.administrator doesn`t exist in 6.1.

I am facing "coldfusion.runtime.TemplateNotFoundException: File not found:" errors in exception.log file, for those files which are no longer exists on my server(no need of use). I don't know why these errors are coming. My website is running properly but why these errors and from where these errors coming to log file, i dont have any idea. Could somebody help me to get out of these errors.