Ahem...
<cfcomponent output="No">
<cffunction
name="init"
returntype="client"
output="no"
>
<cfargument name="datasource" type="string"
required="yes">
<cfargument name="clientId" type="string"
required="yes">
<cfset obj.datasource = arguments.datasource>
<cfset obj.clientId = arguments.clientId>
<!--- housekeeping --->
<cfquery datasource="#obj.datasource#">
DELETE
FROM clientVariables
WHERE created < <cfqueryparam
value="#dateAdd("m", -3, now())#" cfsqltype="CF_SQL_TIMESTAMP">
</cfquery>
<cfreturn this>
</cffunction>
<cffunction
name="get"
returntype="string"
output="no"
>
<cfargument name="name" type="string" required="yes">
<cfset qry = "">
<cfquery name="qry" datasource="#obj.datasource#">
SELECT val
FROM clientVariables
WHERE clientId = <cfqueryparam
value="#obj.clientId#" cfsqltype="CF_SQL_VARCHAR">
AND name = <cfqueryparam
value="#lCase(arguments.name)#" cfsqltype="CF_SQL_VARCHAR">
</cfquery>
<cfreturn qry.val>
</cffunction>
<cffunction
name="set"
returntype="client"
output="no"
>
<cfset var arg = "">
<cfset clear(structKeyList(arguments))>
<cfloop collection="#arguments#" item="arg">
<cfquery datasource="#obj.datasource#">
INSERT INTO clientVariables
(
clientId,
name,
val,
created
)
VALUES (
<cfqueryparam value="#obj.clientId#" cfsqltype="CF_SQL_VARCHAR">,
<cfqueryparam value="#lCase(arg)#" cfsqltype="CF_SQL_VARCHAR">,
<cfqueryparam value="#arguments[arg]#" cfsqltype="CF_SQL_VARCHAR">,
<cfqueryparam value="#now()#" cfsqltype="CF_SQL_TIMESTAMP">
)
</cfquery>
</cfloop>
<cfreturn this>
</cffunction>
<cffunction
name="clear"
returntype="client"
output="no"
>
<cfargument name="names" required="yes">
<cfquery datasource="#obj.datasource#">
DELETE
FROM clientVariables
WHERE clientId = <cfqueryparam
value="#obj.clientId#" cfsqltype="CF_SQL_VARCHAR">
AND name IN
(<cfqueryparam value="#lCase(arguments.names)#"
cfsqltype="CF_SQL_VARCHAR" list="Yes">)
</cfquery>
<cfreturn this>
</cffunction>
</cfcomponent>
-----Original Message-----
From: Matthew Walker
Sent: Friday, 16 December 2005 10:07 a.m.
To: '[email protected]'
Subject: RE: Performance Problem - Client Variables
People seem to have no end of problems with client variables. One
problem is they are a database hit on every request whether you use them
or not. Another is that bots fill up your database and then weird things
start happening (see my thread yesterday "RSS looks ok but not ok"). We
found that cookie client vars were overflowing on one site so switched
to db vars. The performance impact was surprisingly large given it was
only one db hit.
In the end, I wrote a CFC (which is initialised into a session var) that
we use as a client var store instead. It simply reads and writes data to
and from a database table, but it only does it as needed. Seems to work
well.
CFC pasted below if anybody's interested.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Logware (www.logware.us): a new and convenient web-based time tracking
application. Start tracking and documenting hours spent on a project or with a
client with Logware today. Try it for free with a 15 day trial account.
http://www.houseoffusion.com/banners/view.cfm?bannerid=67
Message: http://www.houseoffusion.com/lists.cfm/link=i:4:227116
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe:
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54