StructClear and the Client Scope

The other day I was building a quick demo of an application which used client variables for session management. On logout I was just doing StructClear(client) to clear the client scope. It has been awhile since I have worked on login code for a application which uses client variables for session management, but this is an approach you see used quite often for clearing variables in the session scope on logout.

Well, after logging out using this method I started to see the following error in the ColdFusion logs:

at coldfusion.runtime.Cast._double(
at coldfusion.runtime.Cast._int(
at coldfusion.runtime.ClientScope.UpdateGlobals(
at coldfusion.runtime.ClientScopeServiceImpl.PersistClientVariablesForRequest(
at coldfusion.filter.ClientScopePersistenceFilter.invoke(

Some quick googling led me to comments in the ColdFusion Livedocs which in turn pointed me in the right direction. StructClear was actually deleting the "read-only" Client variables (CFID, CFToken, URLToken, HitCount, TimeCreated, and LastVisit) and this was causing the error. According to the Livedoc comments it is really only the HitCount variable which causes the issue, but the ColdFusion documentation does say:

ColdFusion lets you delete or change the values of the built-in client variables. As a general rule, avoid doing so.

Given this I updated my logout code to use the ColdFusion ClientVariable functions and all was well:

<cfloop list="#GetClientVariablesList()#" index="var">
<cfset DeleteClientVariable(var) />

I'm pretty sure I knew this at one point, but like I said it has been so long since I've done anything like this with the client scope I had totally forgotten about those ClientVariable functions.

tim's Gravatar Thanks!...this post may be old but it solved my issue perfectly.
# Posted By tim | 8/28/09 10:45 AM
BlogCFC was created by Raymond Camden. This blog is running version 5.8.001.