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

* 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

Absolute path of cache directory.

timespan

The interval until the page is flushed from the cache.

expireurl

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

A username

password

A password

port

Remote port to which to connect

protocol

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

value

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

metadata

Name of the struct variable

stripwhitespace
Default: NO

Reduces whitespace

throwonerror

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

Id of the cached object

key

key to access cache

usecache
Default: YES

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

dependson

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

idletime

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

cachedirectory

Cache directory

name

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

Examples sample code using the cfcache tag


Adding a page to the cache

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>


Flushing a page from the cache

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