Keep Symfony2 sessions through cache:clear

By default Symfony2 stores session information in its cache directory. Clearing the cache thus logs everyone out: this small guide will let you how to keep the session even if cache is cleared.

Set save_path

A simple solution is moving where Symfony saves its sessions.

You can do this by configuring the framework bundle via our app/config/config.yml. For example, if you want to store the session info in folder /app/var/sessions, simply put:

        save_path: %kernel.root_dir%/var/sessions

That one line save_path setting will redirect session data to /app/var/sessions. Problem solved!

Capifony hint

If you are also using Capifony (and you should!) then remember to share the sessions between releases, in your deploy.rb.

set :shared_children, [app_path + "/var"]

Originally published on As specified, this material is shared with Creative Commons Attribution-ShareAlike 3.0 Unported License.

  • 2013-07-30 Pont

    Another cool way is to use memcached sessioin handler

  • 2013-05-22 Brian Debuire

    Another good alternative (and more scalable) is to use the database to store the session data: