CFCACHE |
Description
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.
Category
Page processing tags
Syntax
    <cfcache
       action = "action"
       directory = "directory_name"
       timespan = "value"
       expireURL = "wildcarded_URL_reference"
       username = "username"
       password = "password"
       port = "port_number"
       protocol = "protocol">
See also
cfflush, cfheader, cfhtmlhead, cfsetting, cfsilent
History
ColdFusion MX: Deprecated the timeout and cachedirectory attributes. They might not work, and might cause an error, in later releases. Added the timespan attribute. Changed how pages are cached: the default action attribute value, cache, caches a page on the server and the client. (In earlier releases, this option cached a page only on the server.) Changed the source of the protocol and port values: the default protocol and port values are now taken from the current page URL. (In earlier releases, they were "http"and "80", respectively.) Changed how session state is handled when caching a page: this tag can cache pages that depend on session state, including pages that are secured with a ColdFusion login. (In earlier releases, the session state was cleared when caching the page, causing authentication to be lost.) Changed how files are cached: this tag uses a hash() of the URL for the filename to cache a file. (In earlier releases, ColdFusion used the cfcache.map file.)
Usage
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.
Example
    <!--- 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>

ACTION |
| Optional
Default value: "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
Default value: "cf_root/cache " Absolute path of cache directory.

TIMESPAN |
| Optional
Default value: "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
Default value: "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
Default value: "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
Default value: "The current page protocol" Protocol that is used to create URL from cache. http:// https://