Adam Howitt's Blog

Jan 05
2009

Three finds

I was waiting for a server to reboot earlier today and grabbed my copy of CF8 WACK Volume 2 to read Chapter 31 on improving performance and was glad to find two new tips.  CFCache helps you serve popular pages faster and blockfactor on queries is supposed to make your queries return data faster.

CFCache

I'm not sure how I missed this tag in 9 years of CF usage but it rocks.  Add it to a page bfore anything is outputted to the screen and CF adds both client and server side caching mechanisms!

<cfcache action="cache" timespan="#createTimeSpan(0,1,0,0)#">

Using "Cache" as the action attribute turns on both server and client side caching or you can turn on just one or the other.  

In the example above CF saves the output to your server in the cache directory under your CF installation as an MD5 hash of the script name and query parameters.  Subsequent requests within the hour will be served from this file.  

The client side portion tells the visitor browser the update time of the page such that when a subsequent request is sent, the browser passes that date for CF to compare against it's timespan.  If it has expired, it sends a new copy, otherwise it tells the browser to serve the copy it has.

The book points out that pages using session, client or cookie scopes shouldn't use cfcache because the browser won't cache a copy for each session and your cache will contain data tied to just one session - leading to the wrong info being served to different visitors.

Blockfactor

The second find was the blockfactor attribute for CFQUERY.  The theory is that adding blockfactor to queries returning over 100 rows at a time will be improved but from my tests, I found very little improvement, if any.   I'm connecting CF8 to a remote MySQL 5.1 server.  A little googling revealed Ben Nadel's post from 2006 showing similar results.  One commenter pointed out that Oracle is really the only DBMS that can really use this instruction whereas another poster said that it depends on the datasize of the rows you work with.  If anyone has an update on this, I'd love to get some additional perspective.

CFCache revisited

Just for the sake of committing this to memory, I ran into trouble with CFCache returning Connection failure.  CFCache uses CFHTTP under the hood so a little googling took me to a technote about troubleshooting cfhttp.  I vaguely recalled looking at this before on the server and came across Stephen Erat's post on compression.  If you are running CF7 on Windows 2003 and IIS with compression turned on, chances are your CF Scheduled Tasks appear to be failing when you try to run them in a browser and CFHTTP calls against the box fail.  To fix it, I disabled DEFLATE as a compression option, leaving GZIP and everything started working again.  For a guide on how to enable compression on IIS see AhpHosting's guide or look at your IIS documentation.

My change based on the AHP Hosting guide was to remove CF from the scriptfileextensions list:

cscript.exe adsutil.vbs set W3Svc/Filters/Compression/DEFLATE/HcScriptFileExtensions "asp""dll""exe""aspx"
iisreset.exe /restart

Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
[Add Comment] [Subscribe to Comments]
  1. I find things all the time that I don't know how I missed. I actually try to make a point of reading CF's entire tag and function list once a year just to find things that I forgot about or somehow missed entirely.

  2. how does cfcache really work for the client side? HTTP ETag?

[Add Comment]