User Guide

Table Of Contents
302 Chapter 13: Designing and Optimizing a ColdFusion Application
<td>#Description#</td>
<td>#salePrice#</td>
</tr>
</cfoutput>
</table>
</cfsavecontent>
<!--- Save the results in the Application scope. --->
<cflock scope="Application" type="Exclusive" timeout=30>
<cfset Application.productCache = ProductCache>
</cflock>
</cfif>
<!--- Use the Application scope variable to display the sale items. --->
<cflock scope="application" timeout="20" type="readonly">
<cfoutput>#Application.ProductCache#</cfoutput>
</cflock>
Reviewing the code
The following table describes the code and its function:
Code Description
<cfoutput>
Welcome to our home page.<br>
The time is #TimeFormat(Now())#.<br>
Your lucky number is:
#RandRange(1,1000)#<br>
<hr><br>
</cfoutput>
Displays the part of the page that must change each
time.
<cflock scope="application" timeout="20"
type="readonly">
<cfset IsCached = IsDefined
("Application.ProductCache")>
</cflock>
Inside a read-only lock, tests to see if the part of the
page that changes infrequently is already cached in
the Application scope, and sets a Boolean flag
variable with the result.
<cfif not IsCached>
<cfsavecontent
variable="ProductCache">
If the flag is False, uses a cfsavecontent tag to save
output in a Variables scope variable. Using the
Variables scope eliminates the need to do a query
(which can take a long time) in an Application scope
lock.
<cfquery dataSource="ProductInfo"
name="specialQuery">
SELECT ItemName, Item_link,
Description, BasePrice
FROM SaleProducts
</cfquery>
Queries the database to get the necessary
information.