开发者

Should I store user data in sessions?

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 :).


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).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜