August 13th, 2013, 11:44 PM
Is it a better practise to store user data in session or retrieve from database
When a user logs in, is it a better practise to store user data in session (on successful log) or store only customer id in a session and retrieve from database on each page load based on that id?
August 14th, 2013, 03:13 AM
If you load the data into the session from the database when a user logs in, and the user then updates their personal information in the database this does not automatically get synced to the session - you would have to write this in manually.
So, with this in mind, it's your call - you're using CI, how/what does this support in this respect?
August 14th, 2013, 08:30 AM
Sessions tend to be faster than databases (especially if you use a memory store like memcache for sessions) so I recommend them. You do have to note, like Northie said, that updating user records means refreshing the session, but that should be easy.
HEY! YOU! Read the New User Guide and Forum Rules
"They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin
"The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002
Think we're being rude? Maybe you asked a bad question
or you're a Help Vampire.
Trying to argue intelligently? Please read this.
August 14th, 2013, 07:00 PM
Good point. Thanks
Originally Posted by Northie