Symfony 2 安全性:不断从用户提供商处重新加载数据? [英] Symfony 2 Security: keeps reloading data from user provider?

查看:22
本文介绍了Symfony 2 安全性:不断从用户提供商处重新加载数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户已经登录时,安全组件会在每次请求时不断从用户提供程序重新加载数据.有没有办法避免这种情况?当您的用户提供程序不在本地数据库中时,例如在网络服务中,这会显着降低系统速度.

When a user is already logged in, the Security component keeps reloading data from the user provider on every reqyest. Is there a way to avoid this? When your user provider is not in a local database, for example, in a webservice, this can dramatically slow down the system.

每次请求我都会得到这个:

On every request i get this:

[2012-08-15 20:07:30] security.DEBUG: Read SecurityContext from the session [] []
[2012-08-15 20:07:30] security.DEBUG: Reloading user from user provider. [] []

推荐答案

通过覆盖 refreshUser 方法,您可以根据您的需要决定是否为每个请求刷新您的用户>UserProviderInterface 您依赖于给定安全上下文的实现.

You can decide wether or not to refresh your user for each request depending on your needs by overriding the refreshUser method of the UserProviderInterface implementation you rely on from a given security context.

请参考以下 API 文档:

Please refer to the following API documentation:

UserProviderInterface.html#method_refreshUser

是否应该由实现来决定用户数据完全重新加载(例如从数据库),或者如果 UserInterface对象可以合并到一些内部用户/身份数组中地图.

It is up to the implementation to decide if the user data should be totally reloaded (e.g. from the database), or if the UserInterface object can just be merged into some internal array of users / identity map.

这篇关于Symfony 2 安全性:不断从用户提供商处重新加载数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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