Caching Queries -- Duh Moment
In playing with caching CFMX queries, I kept bumping up against the scope of the cached query. If I created a cached query, but stored it in a CFC or UDF, I couldn't always get a page to refer to the recordset due to scoping limitations.
I wanted a query that only updates occaisionally or not at all (such as a list of states, or sales tax tables) but is available to all pages of my site w/o regard to the page. I have to make sure the query is run and the values cached into a memory variable, such as request, or application in my application.cfc.
This worked perfectly, but in a complete DUH moment, I never realized that the query structure could also be referenced as a CFDUMP anywhere on my site.
In application.CFC:
<cfquery name='foo' datasource="#request.datasource#" cachedwithin="#createTimeSpan(0,1,0,0)#">
select * from snoo
</cfquery>
<cfset request.foorecords = foo>
or
<cfset application.foorecords = foo>
Then in any other page that I need to call the variables, I can just use request.foorecords as the query. So
<cfoutput query='request.foorecords'>
<cfloop query='request.foorecords'>
<cfdump='#request.foorecords#'>

There are no comments for this entry.
[Add Comment]