Cleaning the Session Store

November 21st, 2006 by Jack

If you use the Active Record Store as your Session Store, keep in mind that it is inserting rows into a database table for each new HTTP session. Over time, this can accumulate a lot of sessions (one of our products had 800,000 after a few months), most of which are stale.

Luckily, we quickly found the answer at RealityForge : a quick and clean class run by script/runner from a cronjob.
However, our application was using the Bundled Resource plugin which copies static file bundles during each application initalization, which was causing our SessionCleaner to die. This was a pretty easy fix:

RAILS_BUNDLES=no /var/www/application/current/script/runner -e production "SessionCleaner.remove_stale_sessions"

Posted in ruby on rails |

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.