for one sentence, so I'll pick it apart:
>However, if you lock the intantiation of the component without
>requiring read locks
You lost me there. Sorry, if it's a couple-liner, would you show me in
code?
>then you can pull all the CFLOCK tags inside the CFC
>(when it manipulates instance data)
Actually, is it only instance data that I have to worry about? As a
matter of fact, none of my methods modifies instance data, they only
read the instance variables.
>so your code isn't littered with CFLOCKs.
My CFC follows, in case it helps.
Thanks again,
Jamie
<cfcomponent name="helpDef">
<!--- call init() automatically when the CFC is instantiated --->
<cfset init()>
<cffunction name="init" access="public" output="no"
returntype="helpDef">
<cfscript>
// the following querySim has been shortened for this example
request.querySim("
definitionQry
termId, type, term, definition, example
communityResults | component | Community Results | Measureable,
long-term outcomes achieved by individuals, families, and communities.
|
programResults | component | Program Results | Short-term outcomes
related to unit leadership, informal networks, and program agencies. |
communityCapacity | component | Community Capacity | The extent to
which community members demonstrate a sense of shared responsibility
for their community and a collective competence (i.e., a community's
belief in its capability) to respond to community challenges. |
");
// cache queries for a long time (30 days)
cacheSpan = createTimeSpan(30,0,0,0);
// alternate nil span for clearing query caches
nilSpan = createTimeSpan(0,0,0,0);
</cfscript>
<cfreturn this>
</cffunction>
<cffunction access="public" name="getTerm" output="false"
returntype="query">
<cfargument name="termId" type="string" required="false"
default="all">
<cfargument name="type" type="string" required="false">
<cfargument name="clearCache" type="boolean" required="false"
default="false">
<cfset var term = ""><!--- local-scoping the query --->
<cfif clearCache>
<cfset cacheSpan = nilSpan>
</cfif>
<cfquery name="term" dbtype="query" cachedwithin="#cacheSpan#">
SELECT term
FROM definitionQry
WHERE 0=0
<cfif termId is not "all">
AND termId = '#termId#'
</cfif>
<cfif isdefined("type")>
AND type = '#type#'
</cfif>
</cfquery>
<cfreturn term>
</cffunction>
<cffunction access="public" name="getDefinition" output="false"
returntype="string">
<cfargument name="termId" type="string" required="true">
<cfargument name="type" type="string" required="false">
<cfargument name="clearCache" type="boolean" required="false"
default="false">
<cfset var definition = ""><!--- local-scoping the query --->
<cfset var outStr = "">
<cfif clearCache>
<cfset cacheSpan = nilSpan>
</cfif>
<cfquery name="definition" dbtype="query"
cachedwithin="#cacheSpan#">
SELECT definition
FROM definitionQry
WHERE termId = '#termId#'
<cfif isdefined("type")>
AND type = '#type#'
</cfif>
</cfquery>
<cfif definition.recordcount GT 1>
<cfthrow message="getDefinition()'s query returned more than one
matching record">
<cfelse definition.recordcount LT 1>
<cfthrow message="getDefinition()'s query returned zero matching
records">
<cfset outStr = definition.definition>
<cfreturn outStr>
</cffunction>
<cffunction access="public" name="getItem" output="false"
returntype="query">
<cfargument name="termId" type="string" required="false"
default="all">
<cfargument name="type" type="string" required="false">
<cfargument name="clearCache" type="boolean" required="false"
default="false">
<cfset var item = ""><!--- local-scoping the query --->
<cfif clearCache>
<cfset cacheSpan = nilSpan>
</cfif>
<cfquery name="item" dbtype="query" cachedwithin="#cacheSpan#">
SELECT term, definition
FROM definitionQry
WHERE 0=0
<cfif termId is not "all">
AND termId = '#termId#'
</cfif>
<cfif isdefined("type")>
AND type = '#type#'
</cfif>
</cfquery>
<cfreturn item>
</cffunction>
<cffunction access="public" name="getHTMLFormattedItem"
output="true" returntype="string">
<cfargument name="termId" type="string" required="false"
default="all">
<cfargument name="clearCache" type="boolean" required="false"
default="false">
<cfset var item = getItem(termId="#termID#",
clearCache="#clearCache#")>
<cfset var outStr = "">
<cfsavecontent variable="outStr">
<cfoutput query="item">
<strong>#term#</strong> - #definition#<br>
</cfoutput>
</cfsavecontent>
<cfreturn outStr>
</cffunction>
</cfcomponent>
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]

