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
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.cfmWhen 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.
DemoSee this code running!
DownloadDownload this code as a zip!
CommentsThere are no comments!
Click button to add a comment
PublishedThursday 06 Sep 2012
OriginalThis tutorial has been modified and published with permission of the author. The original tutorial can be found here