Jump to content

[SOLVED] Storing Data in Session


premiso

Recommended Posts

Hello All,

 

Have a question about storing data in session. I have a blog site with users of course. Instead of having to make a call to getUserData() each time I want user data inside a function (or defining it globally) I thought about storing the data in a session variable and doing one of two things. Keeping that throughout the lifetime of the session, and only re-querying if a change has been made since the request was pulled (Date field in the user table of last_modified) or just storing it in session and un setting the data each page.

 

Not sure which (if any) is better. Most likely there will be about 20 fields stored, username, email, and some options the user is able to set which should only be boolean variables. I think storing it in session and testing against the timestamp would work great but before I start coding this for my whole site would like to know some input.

 

Thanks!

Link to comment
Share on other sites

The cost of pulling an entire row compared to pulling one column from the database is not much different.  Not unless there is a LOT of data in that row.  You may save some time in parsing the data though.  I would expect you will see little difference though.

 

But I could be wrong :)  It's always difficult to predict performance.

 

Another option is to store the data in a session, and let the script itself refresh the data only if the script itself makes a change to it.  That means that if some other script modifies the user's data, the change won't show up.  But you do save the trouble of checking to see if it's updated.  Whether or not that works depends on your situation.

Link to comment
Share on other sites

I guess either way I am making a trip to the database. The goal is to have the options available globally (via session). So I guess checking against the timestamp works and just keep the data in session will be how I go. It will definitely be under 5KB so I doubt there will be a problem.

 

Thanks for the input bud.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.