Caching a Query

I l @ ve RuBoard

Caching a querythat is, saving it to memorywill help speed up your application. By saving the results of your query to the server's memory, you save the ColdFusion Server from making a trip to the database to retrieve that information in the future. This is useful when the information in the query will not be changing frequently.

  1. In the firstquery.cfm file from the previous task, add the attribute cachedwithin to your <cfquery> tag.

     <cfquery name="productlist" datasource="products" cachedwithin="">  SELECT * FROM tblProducts </cfquery> 

    By using the cachedwithin attribute you are telling the server to save the query. In the next step, you'll learn how to tell the server to keep the query cached for a specified timeframe.

  2. In the cachedwithin attribute, type #CreateTimeSpan(1,0,0,0)#.

    Your code should now read:

     <cfquery name="productlist" datasource="products"  cachedwithin="#CreateTimeSpan(1,0,0,0)#"> SELECT * FROM tblProducts </cfquery> 

    The createtimespan function tells how long to cache the query. In this case, the query is being cached for one day. Createtimespan can specify a time in days, hours, minutes, or seconds.

    Once the timeframe has passed, the server will rerun the query and save it to memory again.

I l @ ve RuBoard


Macromedia ColdFusion 5. Training from the Source
Macromedia ColdFusion 5 Training from the Source (With CD-ROM)
ISBN: 0201758474
EAN: 2147483647
Year: 2002
Pages: 99
Authors: Kevin Schmidt

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