MACROMEDIA COLDFUSION MX 61-DEVELOPING COLDFUSION MX Develop Manual page 280

Developing coldfusion mx applications
Table of Contents

Advertisement

</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
<cfoutput>
Welcome to our home page.<br>
The time is #TimeFormat(Now())#.<br>
Your lucky number is:
#RandRange(1,1000)#<br>
<hr><br>
</cfoutput>
<cflock scope="application" timeout="20"
type="readonly">
<cfset IsCached = IsDefined
("Application.ProductCache")>
</cflock>
<cfif not IsCached>
<cfsavecontent
variable="ProductCache">
<cfquery dataSource="ProductInfo"
name="specialQuery">
SELECT ItemName, Item_link,
Description, BasePrice
FROM SaleProducts
</cfquery>
<h2>Check out the following specials</
h2>
<table>
<cfoutput query="specialQuery">
<cfset salePrice = BasePrice * .8>
<tr>
<td>#ItemNAme#</td>
<td>#Item_Link#</td>
<td>#Description#</td>
<td>#salePrice#</td>
</tr>
</cfoutput>
</table>
</cfsavecontent>
280
Chapter 13: Designing and Optimizing a ColdFusion Application
Description
Displays the part of the page that must change each
time.
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.
If the flag is False, uses a
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.
Queries the database to get the necessary
information
Displays the sale items in a table. Inside a
tag, calculates each item's sale price and displays the
item information in a table row.
Because this code is inside a
ColdFusion does not display the results of the
tag. Instead, it saves the formatted output as
cfoutput
HTML and text in the ProductCache variable.
Ends the
cfsavecontent
tag to save
cfsavecontent
cfoutput
tag,
cfsavecontent
tag block.

Advertisement

Table of Contents
loading

This manual is also suitable for:

Coldfusion mx

Table of Contents