Should I store user data in sessions?

A simple question, but not such a simple answer. If I store user data in sessions, then I will not need to get this data from the MySQL database. But then this data may become obsolete. If I only store user_id in the session, then I will have to query the database each time for user information, and this can slow down the server. If you have any suggestions, write them.

Thanks:).

+4
source share
1 answer

Usually I just keep the key and only start caching when performance becomes a problem. As soon as you start caching data, you introduce the possibility of errors due to outdated data - you must be sure that you will invalidate the cache when the data changes.

I do object caching in instances of my objects, however, to make sure that I request only once per page request (except when necessary).

+7
source

All Articles