How can I cache a ColdFusion page on the ColdFusion server?
The <cfcache> tag also gives you the ability to cache pages on the ColdFusion server by setting the action attribute equal to "serverCache". This type of caching is perfect for non-personalized pages that have high usage.
Note:
1) The <cfcache> tag should be placed at the top your ColdFusion template.
2) The <cfcache> tag treats each distinct URL combination as its own page. So the output of foo.cfm?key=1 and foo.cfm?key=10 would be cached as separate files.
3) ServerCache caching should not be used for caching client specific pages.
A code sample would look as follows:
action = "serverCache"
directory = "C:/temp/cache"
timespan = "#createTimeSpan(0,1,0,0)#">
This question was written by Jeremy Petersen.
It was last updated on March 2, 2006 at 12:18:40 PM EST.
CFML Referenced
Categories
Comments
Comment made by Barry Whitley on February 27, 2006 at 3:59 PM
Will this work with included templates? For example, say I've got a homepage that mixes a lot of "static" content that only needs to get rebuilt once a day (e.g. articles, news items, etc), but the page also contains some personlized content that needs to change for every user. So can it save the more "static" templates while still providing dynamic content in specific sections that are added in using <cfinclude>'s? Or does this only apply to the entire page as sent to the browser?
Comment made by Jeremy Petersen on February 27, 2006 at 5:16 PM
It is an all or nothing (entire page including includes) cache. Check out the cookbook caching entry 'How can I cache the results of a block of ColdFusion code?' (and the entry comments about using persistent variables) for more help on what you are after.
Comment made by Britt Mileshosky on March 1, 2006 at 7:11 PM
There is a major issue (in my opinion) with caching pages on the server. CF puts a html comment on the first line of the html file with I believe the file name and a time stamp. The problem with this is if you are creating XHTML compatible pages, the first line MUST BE the Doctype Definition - not an HTML comment. Thus I cannot create well formed XHTML / CSS based documents and have them be cached server side on the coldfusion platform. Please tell me there is a fix to this???