Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony 2 Security: keeps reloading data from user provider?

Tags:

php

symfony

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. [] []
like image 645
vinnylinux Avatar asked Aug 15 '12 20:08

vinnylinux


1 Answers

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.

Please refer to the following API documentation:

UserProviderInterface.html#method_refreshUser

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.

like image 154
Thierry Marianne Avatar answered Nov 01 '22 23:11

Thierry Marianne