Submit Your Article
Home Articles News Tutorials Videos Add An Article
Topics: Design Photoshop Programming PHP CSS Java Database Web Development Javascript Ajax
– Close + Open

Find Out More About DevWebPro!

Sign up for the newsletter


» Terms & Conditions

Welcome to the New DevWebPro!

DevWebPro Includes:
  Hundreds Of Tutorials   Developer News
  Unique Gadget Videos   Tons of Topics to Discuss
  Expert Advice   We Will Publish Your Articles

Caching CFCONTENT

By: Raymond Camden
Tuesday, November 20th, 2007
Text: Decrease Font Size Increase Font Size | Print Print Article | Share: Delicious Digg StumbleUpon Post to Twitter Post to Facebook

A few days ago I blogged about a code review I was doing for another client. Yesterday I found another interesting bug in their code. (It is always easier to find bugs in other people’s code.)

The code in question was an API tester for their web site. The page had a nice set of links to let you test all of their XML based responses for their site. I noticed something odd in one test. The first time I ran the test, I got a nicely formatted XML result in the browser. The second time however I got an odd jumble of text.

Viewing the source revealed that the XML was there ok. I took a look at the code and spotted the problem right away. See if you can as well:

<cf_ScopeCache
cachename="foo_#somevar#"
scope="server"
timeout="1800">

<cfset myXML = application.myGateway.getMyXML(args)/>

<CFCONTENT TYPE=”text/xml” RESET=”Yes”>
<CFOUTPUT>#ToString(myXML)#</CFOUTPUT>
</cf_scopecache>

If you don’t recognize cf_scopecache, it is just a caching custom tag. It takes the text result of the stuff inside it and stores it.

And that’s where our problem is. Our caching tag caches the text. But the CFCONTENT tag is a Request specific tag. By that I mean it changes the current request. The first time the page is hit, it will execute, as will all the code inside the scopeCache custom tag. The second time though only the text is returned. CFCONTENT isn’t run. The fix was simple – move the CFCONTENT:

<CFCONTENT TYPE="text/xml" RESET="Yes">
<cf_ScopeCache
cachename="foo_#somevar#"
scope="server"
timeout="1800">

<cfset myXML = application.myGateway.getMyXML(args)/>

<CFOUTPUT>#ToString(myXML)#</CFOUTPUT>
</cf_scopecache>

The same issue would exist if you used CFCACHE on top of the page.

Topics: , ,

About the Author:
Raymond Camden, ray@camdenfamily.com http://ray.camdenfamily.com Raymond Camden is Vice President of Technology for roundpeg, Inc. A long time ColdFusion user, Raymond has worked on numerous ColdFusion books and is the creator of many of the most popular ColdFusion community web sites. He is an Adobe Community Expert, user group manager, and the proud father of three little bundles of joy.
DevWebPro is an iEntry Network ® publication - © 1998-2010 All Rights Reserved