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

  <cfcache>

 cfcache();

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

directory string

Absolute path of cache directory.

timespan Timespan

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:
"*/view.cfm?id=*".

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.
Values:
  • 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
Values:
  • 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)
Values:
  • true
  • false

dependson string

Comma seperated 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"

Examples 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>
</cfcache>

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>

Fork me on GitHub