I try to kill browser cache when user logout. I implement the LogoutSuccessHandlerInterface to extends the onLogoutSuccess method. There is no error but when I logout, I can press back button in browser and I see my profil page => If I refresh this page, I am automatically redirected, so I am correctly logged out.
security.yml
logout:
path: /logout
target: /
invalidate_session: true
success_handler: project_user.handler.logout_handler
services.yml
project_user.handler.logout_handler:
class: Project\UserBundle\Handler\LogoutHandler
Project/UserBundle/Handler/LogoutHandler.php
<?php
namespace Project\UserBundle\Handler;
use Symfony\Component\Security\Http\Logout\LogoutSuccessHandlerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RedirectResponse;
class LogoutHandler implements LogoutSuccessHandlerInterface
{
public function onLogoutSuccess( Request $request )
{
$response = new RedirectResponse( '/' );
$response->headers->addCacheControlDirective( 'no-cache', true );
$response->headers->addCacheControlDirective( 'max-age', 0 );
$response->headers->addCacheControlDirective( 'must-revalidate', true );
$response->headers->addCacheControlDirective( 'no-store', true );
return $response;
}
}
I try with this solution and that works perfectly, but this method is called for each requests (many time for each pages) and caused slowdowns. Please help!
thx