Complete Guide of Client Variables in ColdFusion

Client variables are a storage method to persist information with a client and application and save it between user sessions. Normally I look like an alternative to session variables to store data. The main difference between session and client is we can choose the storage of client variables in ColdFusion development. 

In this post, we are going to discuss the Good and Bad parts of dbase storage. Registry and Cookie I am not considering this blog post since for registry I have mentioned everything other blog post and Cookie I never use for client variables.
Client variables offer the following storage: 

  1. Registry
  2.  Cookie
  3.  Database 

Registry (default): Applicable only for Windows OS. I hate to store in the Registry here is another blog entry explaining why?  

Cookie: Well, every developer should be aware of the pros/cons of cookies, so I am not explaining this here. 

Database: This one is my favorite storage method to store client variables. Since this will work with all platforms, it does not matter if I have huge client variables value. 

Good Part: 

  • There will not be a limitation on the data size of client variables for the database. 
  • Client variables can be used to store complex data by serializing to JSON and we can deserialize it whenever we need it back.

Bad Part: 

  •  ColdFusion will fire a query to look for client variables in the database on every request.
  •  Performance may degrade a little bit due to database access. 

Optimize Client Variables Storage: 

If you have made up your mind to use client variables with a storage database, make sure you have taken the following precautions.

  • Keep client variables database separate from the application database if possible.
  • Purge interval for unvisited users keeps smaller as much as possible. I prefer 2 days, but you can adjust as per your client variables‘ importance, and the frequent visits of your users.
  • Check the box “Disable global client variable updates“: If you are not using 𝚑𝚒𝚝𝚌𝚘𝚞𝚗𝚝and 𝚕𝚊𝚜𝚝𝚟𝚒𝚜𝚒𝚝 records to track your user, I will suggest disabling it. This will reduce the number of database transactions. If this option enables the system will always update 𝚑𝚒𝚝𝚌𝚘𝚞𝚗𝚝and 𝚕𝚊𝚜𝚝𝚟𝚒𝚜𝚒𝚝 variable in a database for every request and this may pact performance. 
  • Since ColdFusion gives the ability to create client variables tables if not already existing in the database, we normally use this option. ColdFusion technology will create the following two tables.
    • CDATA

But ColdFusion does not add any primary key or index to this table. I will suggest adding indexes to both tables as follows.

For CDATA add index for APP,CFID column. 
For CGLOBAL add index for CFID column.

Why do Client Variables Matter?

ColdFusion performs the following query on every request to retrieve client variable.

[𝚌𝚘𝚍𝚎:𝚜𝚚𝚕]𝚜𝚎𝚕] 𝚂𝚎𝚕𝚎𝚌𝚝 𝚍𝚊𝚝𝚊 𝚏𝚛𝚘𝚖 𝙲𝙶𝙻𝙾𝙱𝙰𝙻 𝚠𝚑𝚎𝚛𝚎  = @𝙿𝟷[/𝚌𝚘𝚍𝚎]
[𝚌𝚘𝚍𝚎:𝚜𝚚𝚕]𝚜𝚎𝚕𝚎𝚌𝚝 𝚌𝚏𝚒𝚍,𝚊𝚙𝚙,𝚍𝚊𝚝𝚊 𝚏𝚛𝚘𝚖 𝙲𝙳𝙰𝚃𝙰 𝚠𝚑𝚎𝚛𝚎 𝚌𝚏𝚒𝚍 = @𝙿𝟷  𝚊𝚗𝚍 𝚊𝚙𝚙 = @𝙿𝟸[/𝚌𝚘𝚍𝚎]

Notice WHERE condition and you will get an idea of why I suggest an index. If you have heavy traffic c then both table sizes will increase and may cause slower query performance if purge interval is high and no indexing on the table.

Since we cannot use the stock ColdFusion “session” variables – due to what we summarized before – this opens the door to the need to use ColdFusion’s “client” variables. What is the difference between the two? Here is the list:

  1. Client variables allow data storage via a database and not solely in volatile memory on the specific server like session variables.
  2. Client variables only support simple data types – string, numeric, array, struct – contrasting sessions that allow for full objects – i.e., fully represented 𝙲𝙵𝙾𝙱𝙹𝙴𝙲𝚃𝚂.
  3. The fact that “𝚌𝚕𝚒𝚎𝚗𝚝” variables can be stored in the database instantly shows it to be the only viable option when used with a non-persistent true cluster. The only limitation is how to store complex data in a simple data storage facility such as a client variable.

This is where I open another door to a memento pattern that approves the use of “𝚜𝚎𝚜𝚜𝚒𝚘𝚗” information via the “𝚌𝚕𝚒𝚎𝚗𝚝” variable storage facility allowing for full use in a truly clustered server environment.  

In this blog post, the focus is on client variables, a method to persist information between user sessions and applications as an alternative to session variables. Unlike session variables, which are typically limited to server-side storage, client variables offer flexibility in choosing storage methods such as Registry (for Windows OS), Cookies, or Database.

In ColdFusion development process while Database storage for client variables offers robustness and flexibility, careful planning and optimization are crucial to mitigate potential performance bottlenecks, especially in high-traffic scenarios.

how can we help you?

Contact us at the Consulting WP office nearest to you or submit a business inquiry online.

Get technology solution for your business need