Wednesday, 5 September 2012

Problem Caching Queries with ColdFusion

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.

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.

1 comment:

  1. Hi ! cached for 1 Hours means the query will be rerun after 1 Hour.