<cfcache> is your friend.

      CFML Language Reference

--------------------------------------------------------------------------
      Chapter 1 :  ColdFusion Tags




CFCACHE
CFCACHE allows you to speed up pages considerably in cases where the dynamic
content doesn't need to be retrieved each time a user accesses the page. To
accomplish this, it creates temporary files that contain the static HTML
returned from a particular run of the ColdFusion page.

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

Syntax
<CFCACHE
    ACTION="CACHE" or "FLUSH" or "CLIENTCACHE" or "OPTIMAL"
    USERNAME="username"
    PASSWORD="password"
    PROTOCOL="protocol_name"
    TIMEOUT="#DateAdd(datepart, number, date)#"
    DIRECTORY="directory_name_for_map_file"
    CACHEDIRECTORY="directory_name_for_cached_pages"
    EXPIREURL="wildcarded_URL_reference"
    PORT= "port_number">

ACTION
Optional. Specifies one of the following:

  a.. CACHE -- Specifies server-side caching. The default is CACHE.
  b.. FLUSH -- Refresh the cached page. If you specify FLUSH, you can also
specify the DIRECTORY and EXPIREURL attributes.
  c.. CLIENTCACHE --Specifies browser caching.
  d.. OPTIMAL--Specifies optimal caching through a combination of
server-side and browser caching.
See the Usage section for more information.

USERNAME
Optional. When required for basic authentication, a valid username.

PASSWORD
Optional. When required for basic authentication, a valid password.

PROTOCOL
Optional. Specifies the protocol used to create pages from cache. Specify
either HTTP:// or HTTPS://. The default is HTTP://.

TIMEOUT
Optional. DateTime that specifies the oldest acceptable cached page. If the
cached page is older than the specified datetime, ColdFusion refreshes the
page. By default, ColdFusion uses all cached pages. For example, if you want
a cached file to be no older than 4 hours, code the following:

<CFCACHE TIMEOUT="#DateAdd("h", "-4", Now() )#">

DIRECTORY
Optional. Used with ACTION=FLUSH. Specifies the fully qualified path of a
directory containing the cfcache.map to be used when ACTION=FLUSH. The
default is the directory of the current page.

CACHEDIRECTORY
Optional. Specifies the fully qualified path of the directory where the
pages are to be cached. The default is the directory of the current page.

EXPIREURL
Optional. Used with ACTION=FLUSH. EXPIREURL takes a wildcarded URL reference
that ColdFusion matches against all mappings in the cfcache.map file. The
default is to flush all mappings. For example, "foo.cfm" matches "foo.cfm";
"foo.cfm?*" matches "foo.cfm?x=5" and "foo.cfm?x=9".

PORT
Optional. The port number of the web server from which the page is being
requested. The port number defaults to 80. The port number is useful because
the CFCACHE code calls CFHTTP. If the port number is specified correctly in
the internal call to CFHTTP, the URL of each retrieved document is resolved
to preserve links.

Usage
In its simplest form, all you need to do is code <CFCACHE> at the top of a
page for it to be cached.

With the ACTION attribute, you can specify server-side caching, browser
caching, or a combination of server-side and browser caching. The advantage
of browser caching is that it takes no ColdFusion resources because the
browser stores the pages in its own cache, thus, improving performance. The
advantage of using a combination of the two forms of caching is that it
optimizes performance; if the browser cache times out, the server can
retrieve the cached data from its own cache.

In addition to the cached files themselves, CFCACHE uses a mapping file to
control caching. It is named cfcache.map and uses a format similar to a
Windows INI file. The mapping of a URL with parameters is stored as follows.
Assume a directory "c:\InetPub\wwwroot\dir1" that has a CFM file called
"foo.cfm", which can be invoked with or without URL parameters. The
cfcache.map file entries for foo.cfm will look like this:

 [foo.cfm]
Mapping=C:\InetPub\wwwroot\dir1\CFCBD.tmp
SourceTimeStamp=08/31/1999 08:59:04 AM

[foo.cfm?x=5]
Mapping=C:\InetPub\wwwroot\dir1\CFCBE.tmp
SourceTimeStamp=08/31/1999 08:59:04 AM

[foo.cfm?x=9]
Mapping=C:\InetPub\wwwroot\dir1\CFCBF.tmp
SourceTimeStamp=08/31/1999 08:59:04 AM

The cfcache.map file in a given directory stores mappings for that directory
only. Any time the timestamp of the underlying page changes, ColdFusion
updates the cache file for that URL only. ColdFusion uses the
SourceTimeStamp field to determine if the currently cached file is up to
date or needs to be rebuilt.

You can refresh the cache in the following ways:

  a.. TIMEOUT attribute -- ColdFusion tests the timestamp of the cached file
against the TIMEOUT attribute. If the cached file's timestamp is older than
TIMEOUT, the old file is deleted and a new one created. You can use fixed
dates if necessary, but it's preferable to use relative dates. This is the
preferred technique and it works for seconds, hours, days, weeks, years,
etc.
  b.. ACTION=FLUSH -- You use ACTION=FLUSH to force the clean up of cached
files. It can take two attributes, DIRECTORY and EXPIREURL.
  c.. Manually -- Manually or programmatically (using CFFILE) delete the
.tmp files. This is not recommended.
Note the following regarding CFCACHE:

  a.. CFCACHE requires that ColdFusion Server "simultaneous requests" be
greater than 1. When a cache file is generated, the requested page requires
two connections to satisfy the request. When a cached file is found, only
one request is required.
  b.. Debug settings have no effect on CFCACHE unless the template
explicitly turns it on. When generating a cached file, CFCACHE uses
<CFSETTING SHOWDEBUGOUTPUT="No">.
  c.. ColdFusion does not cache pages that are dependent on anything other
than URL parameters.
  d.. To use CFCACHE with the Secure Sockets Layer (SSL), specify
PROTOCOL="http://";.
  e.. If a template returns an error for any reason, the error page gets
cached.
Example
<!--- This example will produce as many cached files as there
    are possible URL parameter permutations. --->
<CFCACHE TIMEOUT="#DateAdd("h", "-4", Now() )#">
<HTML>
<HEAD>
<TITLE>CFCACHE Example</TITLE>
</HEAD>
<BODY>
<H1>CFCACHE Example</H1>

<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>
</BODY>
</HTML>


Todd

----- Original Message -----
From: "Michael Ross" <[EMAIL PROTECTED]>
To: "CF-Talk" <[EMAIL PROTECTED]>
Sent: Wednesday, August 15, 2001 9:18 AM
Subject: Thoughts


| I think I know what everyone has to say about this but I thought I would
share.  A web manager here has asked one of the developers to change an app
they built.  The current one is all db driven, it has a few pages to display
about 110 pages worth of info.  Well the manager wants them to make all the
pages static.  To have them hard coded.  The manager says that because the
info is only updated once in a blue moon they don't need the extra calls to
the db.  Well the developer called me to find out where they could find info
on why this would be a bad idea.....
|
| any thoughts!!!!


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Structure your ColdFusion code with Fusebox. Get the official book at 
http://www.fusionauthority.com/bkinfo.cfm
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Archives: http://www.mail-archive.com/cf-talk@houseoffusion.com/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to