Optimizing ColdFusion Applications


You can use good coding practices and database design to develop efficient applications. Caching the ColdFusion pages or data that is used infrequently is one way of improving performance. ColdFusion MX Administrator provides caching options for ColdFusion pages and SQL queries.

Although ColdFusion performs all the logic and processing required for producing reports or displaying results, this activity is unnecessary if the results don't change frequently.

After processing a page request, the <CFCACHE> tag caches the HTML code in a temporary file on a server. The next time the same page is requested, the page is returned from the cache.

When ColdFusion receives a request for an already cached ColdFusion page, it retrieves the cached HTML pages without processing the ColdFusion page.

Since the caching mechanism considers each URL to be a separate page, it caches a separate page for each unique set of URL parameters.

The <CFCACHE> tag cannot cache templates that generate errors. By default, this tag suppresses all debugging information for the template. It allows you to specify the information using these attributes:

  • ACTION. Specifies whether to cache the page results on the server, the client system, or both. The default value is Cache, which caches the page on the client as well as server side. ClientCache caches the page in the client's browser, while Optimal caches the page using both server-side and browser caching. If the pages contain sensitive, client-specific information, set ACTION to ClientCache.

  • TIMEOUT. Specifies how long the page lasts in the cache, from when it's stored until it's flushed automatically. This is a date/time value that specifies the oldest acceptable page. This attribute is deprecated and might not work well in ColdFusion MX. The new attribute is timespan, which is used to specify the interval until the page is flushed from the cache.

  • CACHEDIRECTORY. Specifies the entire path of the directory on the server where the cached pages are to be stored. This attribute is also deprecated and might not work well in ColdFusion MX.

You can specify several other attributes to access a cached page on the Web server. These attributes include end user name, password, port, and protocol.

For example, this <CFCACHE> tag tells ColdFusion to cache the page on both the client and the server:

 <CFCACHE timespan="#CreateTimespan(1, 0, 0, 0)#"           directory="f:/temp/cached_pages"> 

The page is cached in the f:/temp/cached_pages directory of the server. ColdFusion flushes the cache after the time specified in Timespan is passed. Here, the cached page is retained for one day. You can use the <CFCACHE> tag with the action="flush" attribute to perform a flush immediately.

In certain applications, the ColdFusion page contains a combination of dynamic and less frequently changed information. In such cases, you cannot use the <CFCACHE> tag to cache the entire page. Use the <CFSAVECONTENT> tag to cache the infrequently changed content.

This tag saves the results in a variable. Save the output in the application scope if the information is to be used throughout the application. If it's client-specific, use the session scope. The syntax of <CFSAVECONTENT> tag is

 <CFSAVECONTENT  VARIABLE = "variable name">   the content </CFSAVECONTENT> 

Specify the name of the variable that will save the generated content of the tag.

If you're using a database whose content doesn't change rapidly, cache the query results between page requests. Use the CACHEDWITHIN attribute of <CFQUERY> tag. This attribute is discussed in detail in Chapter 5, "Accessing Databases Using ColdFusion MX."

The <CFSTOREDPROC> tag stores procedures in your database management system. A stored procedure is a sequence of SQL statements that's assigned a name, compiled, and stored in the database system. For more information on SQL statements, read Chapter 5. Stored procedures are faster than <CFQUERY> tags because they are precompiled. The syntax of the <CFSTOREDPROC> tag is

 <CFSTOREDPROC  PROCEDURE = "procedure name"   DATASOURCE = "ds_name"> 

The PROCEDURE attribute contains the name of the procedure stored on a database server. The DATASOURCE variable contains the name of the data source, which points to the database containing a stored procedure.

The <CFPROCPARAM> tag sends parameters to the stored procedure. The <CFPROCRESULT> tag receives the recordsets returned by the stored procedure.




Macromedia ColdFusion MX. Professional Projects
ColdFusion MX Professional Projects
ISBN: 1592000126
EAN: 2147483647
Year: 2002
Pages: 200

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net