Hey everybody,
I'm new to the list, so please excuse my question if it has already been
answered (or feel free to point me to an online archive if one exists).
I'm currently defining some coding conventions for a consulting firm, and
I'd like to get everyone's opinion on the usage of cfinvoke and cfobject. I
think my question is asked more accurately with an example, so here's a
quick CFC and a couple different ways to call it that we can use as a basis
of discussion..
This is a very simple example of a situation where a programmer wants to
select a USER record based on a user_id pk value.
<!--- user.cfc --->
<cfcomponent>
<cffunction name="GetUser" returnType="Query" access="public">
<cfargument name="user_id" type="numeric" required="yes" hint="Any
USER.user_id value.">
<cfinvoke method="Q_selectUser" returnVariable="Q_user">
<cfinvokeargument name="user_id" value="#Arguments.user_id#">
</cfinvoke>
<cfreturn Q_user>
</cffunction>
<cffunction name="Q_selectUser" returnType="Query" access="private">
<cfargument name="user_id" type="numeric" required="yes" hint="Any
USER.user_id value.">
<cfquery name="Q_user" datasource="#Request.dsn#">
SELECT *
FROM USER
WHERE USER.user_id = <cfqueryparam
value="#Arguments.user_id#"
cfsqltype="cf_sql_integer">
</cfquery>
<cfreturn Q_user>
</cffunction>
</cfcomponent>
There are two functions in that CFC..
1) GetUser (public function for templates to call)
2) Q_selectUser (private function that can be made more complex as more
public functions are built that will use it)
Now, a programmer that wants to use this module has a couple choices..
1) Use cfobject
<cfobject action="Create" component="user" name="UserComponent">
<cfset Q_user = UserComponent.GetUser(1)>
2) Use cfinvoke
<cfinvoke method="GetUser" component="user" returnVariable="Q_user">
<cfinvokeargument name="user_id" value="1">
</cfinvoke>
Now here are my questions..
1) Which one will perform better in a very high traffic environment?
2) Are there any significant disadvantages to either method?
3) If the same template was going to use more methods in the CFC, would
there be extra parsing time necessary for subsequent cfinvoke calls?
Thanks a ton for any comments you may have, it's always great to have a pool
of resources to draw on for questions like this..
- j.
----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email
to [EMAIL PROTECTED] with the word 'unsubscribe cfcdev'
in the message of the email.
CFCDev is run by CFCZone (www.cfczone.org) and supported
by Mindtool, Corporation (www.mindtool.com).
An archive of the CFCDev list is available at www.mail-archive.com/[EMAIL PROTECTED]