CFCACHE and the Fall of Rome

This post is more than 2 years old.

I'm not a huge fan of the CFCACHE tag. It's a blunt instrument and I wish CF would natively roll in a nicer caching system (like, oh say, ScopeCache, not that I'm biased or anything). A user wrote in with a question about CFCACHE. Turns out that when you use cfcache, it outputs a HTML comment before the text which can totally break some browsers.

Luckily - this was actually one of the things fixed in 8.0.1.

Unluckily for the user - he was still on ColdFusion 7.

I thought I'd try to get fancy and use onRequest - another feature I'm not a big fan of - but this seemed like a perfect use for it. I tried something like so:

<cffunction name="onRequest" returnType="void"> <cfargument name="thePage" type="string" required="true"> <cfset var content = ""> <cfsavecontent variable="content"><cfinclude template="#arguments.thePage#"></cfsavecontent> <!--- look for comment at beginning ---> <cfset content = rereplace(content, ""^<!--.*?-->$"", "")> <cfoutput>#content#</cfoutput> </cffunction>

At first - this did nothing. Then I remember that the default behavior of cfcache is to cache both on the client and the server. I switched my cfcache tag to use action=servercache, but unfortunately, you can't use cfcache inside custom tags, and that includes tags like cfsavecontent.

Raymond Camden's Picture

About Raymond Camden

Raymond is a senior developer evangelist for Adobe. He focuses on document services, JavaScript, and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

Lafayette, LA https://www.raymondcamden.com

Archived Comments

Comment 1 by Bryan Rapp posted on 4/18/2008 at 12:25 AM

It not only breaks some browser rendering, it breaks most XML parsing as I learned while trying to implement some basic RSS/Atom feed caching. I was disappointed to see the problem was still in CF8, but very glad to learn it was fixed in 8.0.1. I ended up just using cfschedule to cache higher traffic feeds. It works fine for a few things, but could be tough to manage with a large number of pages.

Comment 2 by Steve Bryant posted on 4/18/2008 at 1:00 AM

Would something taking advantage of getPageContext() work? I have had to do content replacement with that before.

<cfset content = getPageContext().getOut().getString()>
<cfset content = rereplace(content, "^<!--.*?-->$", "")>
<cfcontent reset="Yes">
#content#

Untested - I am just spit-balling.

Comment 3 by Raymond Camden posted on 4/18/2008 at 1:03 AM

Wow, that's a no - cuz even without the cfsavecontent it fails. It must be that it's being used inside a CFC method.

Comment 4 by David posted on 4/22/2008 at 12:44 PM

You could use the content filter function of FusionReactor?

Comment 5 by Kevin Penny posted on 9/18/2008 at 7:47 PM

Even though it states in the release notes that the cfcache 'heading' comment has been fixed for xhtml compliance in 8.01 release - and states in the release notes that it has been fixed - "70372 The cfcache tag inserted a comment that invalidated XHTML and XML
pages.
Tags - cfcache"

it's still appearing in our headers on an 8.01 upgraded server (we're not the only ones http://software.groupbrowse...

Any one still seeing this after an upgrade?

Comment 6 by Joel posted on 10/14/2008 at 11:45 PM

I posted the message you linked to. :) Unfortunately I'm back here because I'm still searching for an answer. It's perplexing, given that Adobe says they've fixed this bug.

Comment 7 by Matt posted on 3/11/2009 at 8:12 PM

Ditto on this, just tried cfcache on my server and still have this comment tag appearing breaking xhtml compliance.

how annoying!