Friday, October 04, 2002

How CFMX creates the filename for the compiled version of your CF code

In previous bog entries I've talked about compilation and precompilation of CFMX code into Java. One thing that's been a mystery to many is how CF decides to name the files it creates. Since all CF templates (from all directories) get compiled into the same [cfusionmx]\wwwroot\WEB-INF\cfclasses directory, without any rendering within subdirectories there, there needs to be a way for CFMX (and us) to associate a given file with its source directory.

A CF template named Setsession.cfm might lead to a class file named cfsetsession2ecfm1011928409.class. The numbers that follow the 2ecfm are a hashing of the directory name. Here are the details from Mike Nimer at Macromedia:

How CFMX creates the .class name, or how you can find the name of the .class file you want to delete

The formula is: "cf" + filename + hashCode

The fully canonicalized filename is used, with "/" as the directory separator. The following substitutions are made in the filename:
1.) / becomes __
2.) any other character which would be illegal in a Java identifier is represented as 2 hex digits

hashCode is the hashCode() of the File object which represents this file as documented at http://java.sun.com/j2se/1.3/docs/api/java/lang/Object.html#hashCode()

If the hashCode() is negative, it is exclusive-OR'd with 0xFFFFFFFF to get the value used by ColdFusion.

Note that even two files in the same directory could end up with hashcode values that are different. You can prove this by creating two templates in the same folder, with distinctive names that you can readily identify, and then save and execute those pages, and view the latest class files created in the cfclasses folder. Do both those distinctively named files in the same folder show having the same or different codes? If anyone may be able to help understand how that can happen, I'd love to hear.

No comments: