hpvic03
Technical User
- Aug 2, 2006
- 89
How do i put a cfquery in my application file so that the query runs on every page in that directory?
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
<cfif NOT structKeyExists(application,"isReady") OR sructKeyExists(url,"reset")>
<cfquery datasource="" name="application.yourquery">
select whatever
</query>
<cfset application.isReady = 1>
</cfif>
<cfparam name="loadMyQuery" default="false">
<cflock scope="application" type="readonly" timeout="10">
<cfif not isDefined('application.myQuery')>
<cfset loadMyQuery = true>
</cfif>
</cflock>
<cfif loadMyQuery>
<cfquery datasource="yourDSN" name="getData">
SELECT ... FROM ... WHERE ...
</cfquery>
<cflock scope="application" type="exclusive" timeout="30">
<cfset application.myQuery = getData>
</cflock>
</cfif>
On a very busy site, caching to the hour or even shorter can save huge ammounts of db server time, while keeping data pretty fresh.