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 CFML 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.



Attribute Reference

action string

* 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".
  • cache
  • flush
  • clientcache
  • servercache
  • optimal
  • get
  • put

directory string

Absolute path of cache directory.

timespan numeric

The interval until the page is flushed from the cache.

expireurl string

Used with action = "flush". A URL reference. CFML
matches it against the mappings in the specified cache
directory. Can include wildcards. For example:

username string

A username

password string

A password

port numeric

Remote port to which to connect

protocol string

Protocol that is used to create URL from cache.
  • http://
  • https://

value string

For action="set", object which needs to be stored

metadata string

Name of the struct variable

stripwhitespace boolean
Default: false

Reduces whitespace
  • true
  • false

throwonerror boolean

A Boolean value specifying whether to throw an error if the
flush action encounters an error. Otherwise the action does not
generate an error if it fails. If this attribute is 'true' you can handle the
error in a cfcatch block, for example, if a specified id value is invalid

id string

Id of the cached object

key string

key to access cache

usecache boolean
Default: true

to use cache or not (if false it will process the content each time)
  • true
  • false

dependson string

Comma separated list of all variables on which this cache would depend

idletime numeric

Flushes the cached item if it is not accessed for the specified time span.

cachedirectory string

Cache directory

name string

name of return variable, valid with action="get"

Sample code using the cfcache tag

Puts HTML page into the cache and uses the cached version on subsequent calls to the page.

<cfcache action='optimal' directory='/path/to/directory' timespan='#createTimeSpan( 1, 0, 0, 0 )#' idletime='#createTimeSpan( 0, 12, 0, 0 )#'>
	<div id="some-id">Hello World!</div>

Expected Result: <div id="some-id">Hello World!</div>

Flushes the 'hello-world.cfm' page from the cache.

<cfcache action='flush' directory='/path/to/directory' expireURL='/hello-world.cfm'></cfcache>

Signup for cfbreak to stay updated on the latest news from the ColdFusion / CFML community. One email, every friday.

Fork me on GitHub