Copy link to clipboard
Copied
This one is driving me nuts...
I have the following piece of code...
<cfquery datasource="#dsn#" name="q" cachedwithin="#createTimeSpan(0,0,30,0)#">
Some fancy SQL
</cfquery>
Today, the above stopped working. The error was variable q was undefined. Odd, figured the caching went wrong, so I changed it to this
<cfquery datasource="#dsn#" name="q" cachedwithin="#createTimeSpan(0,0,0,0)#">
Some fancy SQL
</cfquery>
to empty out the query cache for that query. The query then started to work with the #createTimeSpan(0,0,0,0)#. I change it back to #createTimeSpan(0,0,30,0)# and instantly it dies... variable q undefined. Strange. So I after running it again with #createTimeSpan(0,0,0,0)# it starts to work. I bumped it to #createTimeSpan(0,0,5,0)# it works. I bump it to #createTimeSpan(0,0,10,0)# it works. I bump it to #createTimeSpan(0,0,15,0)# it dies... variable q undefined. After some tweaking, I find out that anything larger than #createTimeSpan(0,0,11,0)# and it returns variable q undefined.
I am beyond confused why this is not working anymore. I'm using Coldfusion10 which is using the new ehcaching mechanism if that makes a difference, but I can't see why it would. The server is a Windows2008R2 w/ IIS 7.5. Anybody have any clues?
Copy link to clipboard
Copied
To elaborate on this further... I know it is 2 months old (I still have not found a solution). It looks as if the caching mechanism is so advanced that if the first run of the query fails (before it is cached), it will cache the crashed query. I know, it sounds odd. If this piece of code executes...
<cfquery datasource="#dsn#" name="q" cachedwithin="#createTimeSpan(0,0,30,0)#">
Some fancy SQL
</cfquery>
And the above crashes, the page will cache the broken query and that means the page will not work until the cache is changed to 0,0,0,0 (or emptied). The page will come back with an error that q does not exist. I have not found a solution yet other than to disable caching on queries that might crash.
Copy link to clipboard
Copied
Check the Caching Server Settings in the ColdFusion Administrator. You might want to flush it. Pay attention with "Trusted cache" and "Cache Template In Request".
Copy link to clipboard
Copied
Trusted cache is off... Cache template in request is on, but I don't see how either of those options would affect a query though because we are talking about queries here, not pages (or am I wrong)?
Flushing the query cache makes everything work again until the process restarts when the query crashes mid run and then the crashed query gets cached.
Copy link to clipboard
Copied
I just worked around the problem with CFTRY
<cftry>
<cfset myResult=GetRecs><!--- Test the query by assigning it to a variable and see if it generates error --->
<cfcatch type="any">
<!--- It does, then redo query with no cache --->
<cfquery datasource="Guide" name="GetRecs" cachedwithin="#CreateTimeSpan(0,0,0,0)#">
select #application.SearchCols# from mytable
</cfquery>
<cfset myResult=GetRecs>
</cfcatch>
</cftry>