0

ColdFusion 8: Append File Faster and Leaner

ColdFusion 8

While the cffile tags are extremely useful they are a bit of a resource hog because they load the actual file into memory. ColdFusion 8 brings new file functions that interact with the file system directly. Last week I saw just how much faster and leaner using these functions is. I needed to loop over a 155,000 line file, do a regular expression on the line and append it to a new file.

Doing this with cffile action="append" I could see the memory increase in the server monitor and it took on average 46 seconds. I then switched out cffile action="append" with the code below, ran it saw no memory increase in the server monitor and it took 20 seconds on average.

<cfset variables.fileobj= fileOpen("/fileLocation/OnYourcomputer/FileName.txt", "append" )>
<cfset fileWriteLine(variables.fileObj,"" )>
<cfset fileClose(variables.fileobj)>

Notice how in the fileOpen function I set the mode to append. Oh, and I was also using cfloop file="" with this which interacts directly with the file and makes looping over files easy.

tags:
ColdFusion 8
Dynamic Developer said:
 
This is another good example of the power of cf 8. It's a great product. It's probably the best advancement so far of the cf products.
 
posted 344 days ago
Add Comment Reply to: this comment OR this thread
 

Search

About Me
I am a 32-year old Web Developer specializing in ColdFusion. I live and work in downtown Washington, DC with my wife and daughter. I work for Interfolio where we help people collect, deliver and showcase their life's work. Read more About Me

2007 CFeMmy Best Newcommer winner
As voted on by fellow CF Bloggers.