Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simultaneous db access: difference between client and session variable

Status
Not open for further replies.

cadoltt

Programmer
Jun 9, 2005
85
CA
Hi Everybody,

I think the problem I need a help for is common for CF developers and experienced programmers should know the best solution for it. I am developing an application which intends to access the database (Oracle) by a few users. Each of them should be able to add records into some table and they are to see and update only their records. From what I read about the variable scope I thought I need to set client variables during login procedure to distinguish between different users if a few of them are working with the table at the same time. However examples of login I found on the Web use session variables.

Can anyone explain to me the difference between client and session variables and tell me which are more suitable for the task I am working on?

Thanks,

Alex
 
In the end, they do just about the same thing, and from the end user's perspective, they even do it in a similar way. Basically, they both set a cookie in the browser, and then when the user clicks to the next page, it sends the cookie, and before CF executes the page, it fetches those variables that were previously set. The difference is that session variables are stored in server's memory, and client variables are stored in a database. One effective difference is that the client variables will persist even if the server reboots, but ideally this should not happen often. Also, session variables are "supposed" to be wrapped in <cflock> which gets annoying to program. Personally, I use client variables almost exclusively, and my server pushes a decent amount of traffic flawlessly. Others may disagree.
 
jmille34,

Thanks for your response. So there are some pros and cons for both. I need to think what can be more appropriate for me.

Tell me waht you mean saying that client vars are stored in a database. What database?

Thanks again,

Alex
 
There are a few ways to do it, but I do it by first setting up a datasource for the application, which you probably already have. Then you go into CFAdmin, and go into the client variables section, and select your datasource from the list, and click next (or whatever, I forget what it says) and it will create I think 2 tables in the database called CDATA and CGLOBAL. Then you go into your application.cfm or where you call <cfapplication> and you add 2 client parameters to it:

<cfapplication name="appname" clientmanagement="Yes" clientstorage="mydatasource" .... etc ... >

From then on, whenever you set a client variable, it will be stored in that database. It's really quite seamless and friendly, and once you set it up, you basically never have to worry about it again.

Internally, what it does is create those 2 tables, and the tables contain columns that coorespond to the cfid and cftoken cookies, and when the user clicks a link on teh site, it sends the cookies, and CF receives the cookies and because your cfapplication uses "clientmanagement" it looks up the cookie variables in those tables, and the other column or columns in the tables are big text fields that contain the contents of your client variables.

Again, I'm being a little loose with these terms, because it is so simple and seamless that after a while, I have just forgotten exactly what it does internally.

Lastly, some people worry that storing data in the database will be slower than memory, and that may be true to a tiny limited extent, but I'm pushing decent traffic on very medium level hardware (2.4ghz p4, sata hard drive, 1g ram), and it is both FAST and FLAWLESS. I have toyed with session variables at times when I'm starting a new app, just because I know people use them and I thought maybe there was more benefit to it that I wasn't seeing, but I always switch back. As far as I can tell, there is no drawback to using client variables, and if there is a reason to prefer session over client, I don't know what it could be, and I imagine it is a somewhat underwhelming reason.
 
jmille34,


I followed the steps you suggested, the only difference was that I had to create those two tables manually. Hope this will work.

Thanks a lot!

Alex
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top