Reputation: 381
Simple question, but not so simple answer. If I store user data into the sessions, then I wouldn't have to get that data from MySQL database. But then that data could get become obsolete. If I store only user_id in session, then I would have to ask database each time for user info and that could lead server to slow down. If you got any suggestions, please write them.
Thanks :).
Upvotes: 5
Views: 1250
Reputation: 171599
Typically I just store the key, and only start caching once performance becomes an issue. As soon as you start to cache data, you introduce the possibility of bugs due to stale data - you must be sure to invalidate the cache anytime you modify data.
I do cache properties on instances of my objects, though, to ensure I am only querying once per page request (except where necessary).
Upvotes: 7