I use active record store for rails sessions store.
Over just a short time, the size of sessions
table has increased a lot. How are these session rows dumped after a certain period of time. Or should I manually clear them once in 24 hours?
I use active record store for rails sessions store.
Over just a short time, the size of sessions
table has increased a lot. How are these session rows dumped after a certain period of time. Or should I manually clear them once in 24 hours?
Use a standard call to ActiveRecord in Rails 3.2. For the date, pass a value that matches the length of your "Remember me" duration. In my example, this will clear ALL sessions that have been inactive for two weeks.
As stated by @journeyer below, if using the Devise gem, one can reference the Devise' configuration.
If using the Sorcery gem, one can reference the Sorcery's configuration.
When you call
reset_session
rails will delete that row from the session table. However not every session will havereset_session
called on it: if a user closes their browser without logging out then the browser will discard the session cookie, so that session row will never be used again, butreset_session
won't be called.Rails won't clear out that accumulating cruft for you - it's up to you to do any housekeeping on it as you see fit. In a previous job we use to run a cronjob that deleted old session rows.
I would recommend clearing your rails sessions using a cron job or something. Maybe not 24 hours tho, depends on how long you want user sessions available for. Rails provides a rake task for this
A good blog post about your issue : http://blog.brightbox.co.uk/posts/clearing-out-rails-sessions
The solution is to create a custom rake task:
... and run it every day with a cron job.