Let's say, we want to display a list of our blog posts. Since we don't want to query the database all the time, we are going to cache our query for a set length of time. Let's first get the items from our database:
1. In your
<Railo Install>/webroot/Chapter_5
folder, create a template calledquerycache.cfm
with a simple query and a dump of the results:<cfquery name="getPosts" datasource="railoblog"> SELECT * FROM post </cfquery> <cfdump var="#getPosts#">
The output of this query should look something like the following screenshot:
2. At the top of the query, you can see that it says Cached: No
3. Let's add a
cachedwithin
attribute to the<cfquery>
tag:<cfquery name="getPosts" datasource="railoblog" cachedwithin="#CreateTimeSpan(0,0,5,0)#"> SELECT * FROM post </cfquery> <cfdump var="#getPosts#">
When we now run the template a couple of times, we will get the following result:
You can see...