在会话存储用户信息? [英] Store user information in session?

查看:95
本文介绍了在会话存储用户信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您应该存储信息有关每个请求所需要的用户
例如。角色,电子邮件,用户名等。

Should you store info about the user required for each request eg. Role, email, username etc.

在会话,或者是确定转到数据库以获得该信息?

in Session, or is ok to goto the database each request for this information??

感谢

推荐答案

如果你不负载平衡计划,那么会话状态是完全可以接受的。要小心,如果会话状态被配置为使用,虽然数据库持久化,因为这样你不仅可以进入数据库,但招致对象的序列化的开销。

If you're not planning on load balancing, then session state is perfectly acceptable. Be careful if the session state is configured to use database persistence though, because then you'll not only be hitting the database, but incurring an overhead of serialisation of the objects.

如果这是用户特定的数据,则一个分布式散列表的高速缓存系统可能工作。像Memcached的东西也不错对于这一点,因为他们是在内存中缓存(性能),但在多台服务器(负载平衡)分布,所以你得到两全其美。

If it's user-specific data, then a distributed hashtable cache system might work. Things like Memcached are good for this, because they are in-memory caches (performance) but are distributed across multiple servers (load balancing) so you get the best of both worlds.

当然,如果它是一个定期更换,特别是如果有可能修改数据库没有Web应用程序知道,然后回到数据库,你的其他系统可能是唯一的选择。数据

Of course, if it's data that changes regularly, particularly if you other systems that might modify the database without the web app knowing, then going back to the database might be the only option.

这篇关于在会话存储用户信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆