[thelist] CF -- have a Q need a Tip to clean-up my webs.

Rory.Plaire at wahchang.com Rory.Plaire at wahchang.com
Mon Oct 15 13:32:29 CDT 2001


.jeff graciously noted:

| it is, provided you have a mechanism that makes sure the 
| query only runs if
| it isn't in memory.
| 
| <cflock scope="session" type="exclusive" timeout="10" 
| throwontimeout="no">
|   <cfparam name="session.myqry" default="">
|   <cfif NOT IsQuery(session.myqry)>
|     <cfquery name="myqry" ...>
|       SELECT foo
|         FROM bar
|        WHERE bones <> 'ice cream'
|     </cfquery>
|     <cfset session.myqry = Duplicate(myqry)>
|   </cfif>
| </cflock>
| 

Ok, ok. My first and gut reaction to this is, "Hrwaa? A query in a lock?
Ba... Gaa... That goes against everything I've seen and read!" Then, I
realized that there may be exceptions to the "rules." (See the <read> below
for the source of this reflection.)

Trying to reconcile the two, I think about it this way:

<cflock scope="session" type="exclusive" timeout="5" throwontimeout="no">
	<cfparam name="session.myqry" default="">
	<cfset bQuery = IsQuery(session.myqry)>
</cflock>

<cfif NOT bQuery>
     <cfquery name="myqry" ...>
       SELECT foo
         FROM bar
        WHERE bones <> 'ice cream'
     </cfquery>
</cfif>

<cflock scope="session" type="exclusive" timeout="5" throwontimeout="no">
     <cfset session.myqry = Duplicate(myqry)>
</cflock>


Please be inclined to advise as to the particular strengths and weaknesses
in this approach. 8)


| perhaps your problem is that you're not assigning a simple 
| value to the local variable, but a query which is a 
| complex value and therefore gets copied by reference 
| rather than by value?  try the Duplicate() function
| instead.
...
| <cflock scope="session" type="readonly" timeout="10" 
| throwontimeout="no">
|   <cfset myqry = Duplicate(session.myqry)>
| </cflock>

Yes, of course. I was, however, a little vague on the issue which would
resolve to be: if I am needing to cflock access to a local variable, why
assign the session scoped value to a local one? I hadn't answered that
question before I wanted to make an entreaty on Duplicate(). Which,
incidentally, revolves around performance. I suppose it depends on the code
I am writing, seeing as if I had 1 lock plus 1 Duplicate() vs. 1 lock and 0
Duplicate(), I might just skip assignment to a local variable altogether,
and use <cfloop query="session.myqry"> in a cflock, for instance. This is
what I was wondering -- have you seen this?


<read when="one likes Middle-Eastern philosophy">
"The story is told of a mystic knower, who went on a journey with a learned
grammarian as his companion. They came to the shore of the Sea of Grandeur.
The knower straightway flung himself into the waves, but the grammarian
stood lost in his reasonings, which were as words that are written on water.
The knower called out to him, "Why dost thou not follow?" The grammarian
answered, "O Brother, I dare not advance. I must needs go back again." Then
the knower cried, "Forget what thou didst read in the books of Síbávayh and
Qawlavayh, of Ibn-i-Hajíb and Ibn-i-Málik,[Famed writers on grammar and
rhetoric.] and cross the water." 

  'The death of self is needed here, not rhetoric: 
  Be nothing, then, and walk upon the waves.' [The Mathnaví. (Rumi)]

(Bahá'u'lláh, Seven Valleys)
</read> 

<rory disposition="immensely thankful" alt="8)"/>




More information about the thelist mailing list