View comments | RSS feed
Contents > CFML Reference > ColdFusion Tags > cfcache PreviousNext

cfcache

Stores a copy of a page on the server and/or client computer, to improve page rendering performance. To do this, the tag creates temporary files that contain the static HTML returned from a ColdFusion page.

Use this tag if it is not necessary to get dynamic content each time a user accesses a page.

You can use this tag for simple URLs and for URLs that contain URL parameters.

Page processing tags

<cfcache 
action = "action"
directory = "directory_name"
timespan = "value"
expireURL = "wildcarded_URL_reference"
username = "username"
password = "password"
port = "port_number"
protocol = "protocol">

cfflush, cfheader, cfhtmlhead, cfsetting, cfsilent

ColdFusion MX:

Attribute

Req/Opt

Default

Description

action

Optional

cache

  • cache: server-side and client-side caching.
  • flush: refresh cached page(s).
  • clientcache: browser-side caching only. To cache a personalized page, use this option.
  • servercache: server-side caching only. Not recommended.
  • optimal: same as "cache".

directory

Optional

cf_root/cache

Absolute path of cache directory.

timespan

Optional

Page is flushed only when cfcache action = "flush" is executed

The interval until the page is flushed from the cache.

  • A decimal number of days. For example:

- ".25", for one-fourth day (6 hours)

- "1", for one day

- "1.5", for one and one half days

  • A return value from the CreateTimeSpan function. For example:
    "#CreateTimeSpan(0, 6, 0, 0)#"

expireURL

Optional

Flush all cached pages

Used with action = "flush". A URL reference. ColdFusion matches it against the mappings in the specified cache directory. Can include wildcards. For example: "*/view.cfm?id=*".

username

Optional

 

A username. Provide this if the page requires authentication at the web server level.

password

Optional

 

A password. Provide this if the page requires authentication at the web server level.

port

Optional

The current page port

Port number of the web server from which the URL is requested. In the internal call from cfcache to cfhttp, ColdFusion resolves each URL variable in the page; this ensures that links in the page remain functional.

protocol

Optional

The current page protocol

Protocol that is used to create URL from cache.

  • http://
  • https://

Use this tag in pages whose content is not updated frequently. Taking this action can greatly improve the performance of your application.

The output of a cached page is stored in a file on the client browser and/or the ColdFusion server. Instead of regenerating and redownloading the output of the page, each time it is requested, ColdFusion uses the cached output. ColdFusion regenerates and downloads the page only when the cache is flushed, as specified by the timespan attribute, or by invoking cfcache action=flush.

To enable a simple form of caching, put a cfcache tag, specifying the timespan attribute, at the top of a page. Each time the specified time span passes, ColdFusion flushes (deletes) the copy of the page from the cache and caches a new copy for users to access.

You can specify client-side caching or a combination of client-side and server-side caching (the default), using the action attribute. The advantage of client-side caching is that it requires no ColdFusion resources; the browser stores pages in its own cache, improving performance. The advantage of combination caching is that it optimizes server performance; if the browser does not have a cache of the page, the server can get data from its own cache. (Macromedia recommends that you do not use server-side only caching. Macromedia recommends that you use combination caching.)

If a page contains personalized content, use the action = "clientcache" option to avoid the possibility of caching a personalized copy of a page for other users.

Debug settings have no effect on cfcache unless the application page enables debugging. When generating a cached file, cfcache uses cfsetting showDebugOutput = "No".

The cfcache tag evaluates each unique URL, including URL parameters, as a distinct page, for caching purposes. For example, the output of http://server/view.cfm?id=1 and the output of http://server/view.cfm?id=2 are cached separately.

The cfcache tag uses the cfhttp tag to get the contents of a page to cache. If there is an HTTP error accessing the page, the contents are not cached. If a ColdFusion error occurs, the error is cached.

<!--- This example produces as many cached files as there are 
URL parameter permutations. ---> <cfcache timespan="#createTimeSpan(0,0,10,0)#"> <body> <h3>This is a test of some simple output</h3> <cfparam name = "URL.x" default = "no URL parm passed" > <cfoutput>The value of URL.x = # URL.x #</cfoutput>

Contents > CFML Reference > ColdFusion Tags > cfcache PreviousNext

ColdFusion 8 | ColdFusion MX 7 | ColdFusion MX 6.1 | ColdFusion MX | Forums | Developer Center | Bug Reporting

Version 6.1

Comments are no longer accepted for ColdFusion MX 6.1. ColdFusion 8 is the current version.

Comments


No screen name said on Jan 27, 2004 at 3:24 PM :
Why is it not possible using cfcache to add a parameter

pageencoding="UTF-8"

to save a cached file in UTF-8 format? All files will be saved in "Western (Latin1)" format -- but the original file is UTF-8 encoded using Dreamweaver (CTRL+J > UTF-8). This is terrible, because all cached files will be shown in the wrong encoding, thus special characters are displayed wrong.

Is there a workaround for this bug??
halL said on Jan 30, 2004 at 10:42 AM :
In response to the request to add a parameter to cfcache:

ColdFusion has the opposite problem to the one described.
ColdFusion always returns cfcached pages in UTF-8; that is, with an HTTP header specifying a charset of UTF-8.
We have submitted a bug against this behavior, number 54095, against this behavior.

I believe that the described problem is different, and not related to cfcache.
While Dreamweaver is saving the page as UTF-8 code, ColdFusion is reading the file using the system default encoding, probably Windows-1252 or ISO-8859-1.

To force ColdFusion to read the page as UTF, do either of the following:
In Dreamweaver, select the "Include Unicode Signature (BOM)" option on the Title/Encoding dialog.
OR
Use the following tag at the top of each CFML page that you save in UTF-8:
<cfprocessingdirective pageencoding="UTF-8">

If select to include the BOM in Dreamweaver you do not need to use the cfpageencoding tag on your pages, as ColdFusion will read the BOM (two bytes at the start of the file) and determine the page is UTF-8 automatically.
wlee said on Mar 22, 2004 at 8:05 AM :
We are working to improve the examples in the ColdFusion reference pages. We propose to replace the current example on this page with the the following example. If you have any comments on this example, add them to this page.

<!--- This example produces as many cached files as there are
URL parameter permutations. You can see that the page is cached when the timestamp doesn't change.--->
<cfcache
timespan="#createTimeSpan(0,0,10,0)#">
<body>

<h3>This is a test of some simple output</h3>

<cfoutput>
This page was generated at #now()#<br>
</cfoutput>

<cfparam name = "URL.x" default = "no URL parm passed" >
<cfoutput>The value of URL.x = # URL.x #</cfoutput>
Hallow said on Oct 21, 2004 at 12:04 PM :
This tag ignores cgi.path_info, making pages with parameters passed in a search engine friendly way such as index.cfm/blah1/blah2 unusable.
jsm said on Aug 9, 2005 at 7:04 AM :
CfCache adds an html comment on the first line of the page being cached (server side cached). However, the first line is reserved for the DOCTYPE declaration. With the comment generated by CF, it cancels out the basis of having a doctype declaration, and therefore does not allow standards based, css websites to be integrated with server caching.

In short, MSIE goes into quirks mode and ignores your CSS.
No screen name said on Aug 15, 2006 at 1:18 PM :
to get rid of the comment cfcache puts at the begining, call another template first, use cfhttp to call the original, cached template, then use Replace() to remove the comment

<!--- call the main template, where we use cfcache to cache the response
<cfset theURL = 'http://localhost/main.cfm?' & '#CGI.QUERY_STRING#'>
<cfhttp url='#Variables.theURL#' method="GET">

<!--- remove the comment cfcache puts at the top of cached response, so the response will be XML compatible --->
<cfset theComment = '<!---' & '#Variables.theURL#' & '--->'>
<cfset xmlResponse = Replace('#cfhttp.fileContent#', '#theComment#', '' , "one")>

<!--- send a clean response to the client --->
<cfoutput>#Variables.xmlResponse#</cfoutput> --->

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/coldfusion/6.1/htmldocs/tags-pa8.htm