Add Comment
ColdFusion Cached queries
ColdFusion Tutorial #46
ColdFusion will only cache queries if the SQL used within them stays exactly the same. This also means that the query's
Name,
Datasource,
Database type,
Username & password
must also remain the same. I ran into the mistake of adding the datetime variable Now() for a datetime field, and the query would not cache. Once I realised what the issue was, to get around it I simply used the date + hours portion of Now(), and replaced it in the query.
Below is an example of a query which can be cached for 1 hour.
demo.cfm
When using cached queries, you should always ensure that the 'Maximum number of cached queries' in ColdFusion admin (Server Settings > Caching) is set to a higher number (I found my ColdFusion 9 was set to only cache 1 query). The value should be set depending on the amount of RAM in your server and the performance of your database.Demo
See this code running!
Download
Download this code as a zip!
Comments
There are no comments!Click button to add a comment
Author
Alex Koumoundouros
Published
Thursday 06 Sep 2012Original
This tutorial has been modified and published with permission of the author. The original tutorial can be found herehttp://akoumoundouros.blogspot.com.au/2012/09/problem-caching-queries-with-coldfusion.html