Pritesh Patel Feb,08 2017
Client variables is storage method to persist information with a client and application and saved between user sessions. Normally I look as an alternative of session variables to store data. Main difference between session and client is we have option to choose storage of client variables.
Client variables offers following storage:
Registry (default) : Applicable only for windows OS. I really hate to store in Registry here is another blog entry explaining why?
Cookie : Well, every developer should aware of pros/cons of cookie 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 platform, it doesn't mind if I have huge client variables value.
In this post I am going to discuss Good and Bad part with Database storage. Registry and Cookie I am not considering for this blog post since for registry I have mention every thing my another blog post and Cookie I never use for client variables.
Optimize Client Variables Storage:
If you have make mind to use client variables with storage database make sure you have taken following precaution.
But coldfusion doesn't add any primary key or index on this table. I will suggest to add indexes on both table as follow.
For CDATA add index for APP,CFID column.
For CGLOBAL add index for CFID column.
ColdFusion perform following query on every requests to retrive client variable.
select data from CGLOBAL where cfid = @P1
select cfid,app,data from CDATA where cfid = @P1 and app = @P2
Notice WHERE condition and you will get idea why do I suggest to add index. If you have heavy traffic site then both tables size will increases and may cause slower query performance if purge interval is high and no indexing on table.
Hope this help and always welcome suggestion