User Guide

Table Of Contents
306 Chapter 13: Designing and Optimizing a ColdFusion Application
Using the cfquery tag cachedWithin attribute
The
cfquery tag cachedWithin attribute tells ColdFusion to save the results of a database query
for a specific period of time. This way, ColdFusion accesses the database on the first page request,
and does not query the database on further requests until the specified time expires. Using the
cachedWithin attribute can significantly limit the overhead of accessing databases that do not
change rapidly.
This technique is useful if the database contents only change at specific, known times, or if the
database does not change frequently and the purpose of the query does not require absolutely up-
to-date results.
You must use the
CreateTimeSpan function to specify the cachedWithin attribute value (in
days, hours, minutes, seconds format). For example, the following code caches the results of
getting the contents of the Employees table of the cfdocexamples data source for one hour.
<cfquery datasource="cfdocexamples" name="master"
cachedWithin=#CreateTimeSpan(0,1,0,0)#>
SELECT * FROM Employees
</cfquery>
Providing visual feedback to the user
If an application might take a while to process data, it is useful to provide visual feedback to
indicate that something is happening, so the user does not assume that there is a problem and
request the page again. Although doing this does not optimize your applications processing
efficiency, it does make the application appear more responsive.
You can use the
cfflush tag to return partial data to a user, as shown in Chapter 26,
“Introduction to Retrieving and Formatting Data,” on page 609.
You can also use the
cfflush tag to create a progress bar. For information on this technique, see
the technical article “Understanding Progress Meters in ColdFusion 5” at www.macromedia.com/
v1/handlers/index.cfm?id=21216&method=full. (Although this article was written for
ColdFusion 5, it also applies to ColdFusion MX.)