Published:
Warning: This blog entry was written two or more years ago. Therefore, it may contain broken links, out-dated or misleading content, or information that is just plain wrong. Please read on with caution.
Yesterday I found myself getting tripped up by Coldfusion 9's updated page caching mechanism. I was scratching my head for awhile trying to figure what was going on.
For those of you who have'nt used it before cfcache allows you to cache the output html from a particular template. This is very useful if you have a page that changes infrequently but may take alot of processing/memory to execute or is used frequently on a high traffic site.
Note: The following is not an in depth intro to cfcache, I suggest anybody who has'nt used it before to visit the adobe livedocs for instructions on using it.
CFCache on Coldfusion 8
Previously on CF8 you implemented caching by placing the following line of code at the start of your template before any output was made to the browser. This would cache the output html from the template the first time it was run and use that html cache for subsequent page requests until the timespan had passed.
<cfcache timespan="#createTimeSpan(0,1,0,0)#" >
---code to output html here---
A default behaviour of the caching was that different url parameters would count as different pages so you could use caching for frameworks such as fusebox.
CFCache on Coldfusion 9
In Coldfusion 9 however cfcache is implemented slightly differently. Firstly you can now cache page fragments. This is a useful update however it requires that the cfcache tag must now have a closing tag as follows.
<cfcache timespan="#createTimeSpan(0,1,0,0)#" >
---code to output html here---
</cfcache>
Changing the query string behaviour
Having to use a closing tag for caching is not a big deal, I spent 15 minutes going through all my templates adding a closing tag thinking that was it.
However I was in for a surprise. When I started browsing the site I found that my query string parameters were having no effect on the display. After a few minutes scratching my head and reading the adobe livedocs I found out that what was happening.
In CF 9 the cfcache tag now ignores the query string by default. The adobe livedocs skim over this change in behaviour, however if you read closely you will see that several new attributes have been added to the tag. One of these new attributes is the optional "usequerystring" attribute which has a default value of false.
Reading further you see this note in reference to this attribute:
If true, generates a template cache ID that includes the query string. This means that a new template cache is created whenever the query string changes.".
This means that in order to preserve the behaviour of a site written in CF8 you now need to explicitly tell coldfusion to check the querystring as per the following code snippet.
<cfcache timespan="#createTimeSpan(1,0,0,0)#" useQueryString="true">
---code to output html here---
</cfcache>
Reader Comments