session cleanup

Hi everyone,

I am a newb. Can anyone tell me how to do session cleanup? I want to
cleanup those sessions which haven't been modified in recent 5
minutes. How to make it a background process in my rails application?

thanks in advance,


Do you mean how to timeout a session, or clean up old sessions in the
database (when using table-based session, opposed to cookie-based



yes to which one?

sorry for confusion. for databased session

Here's any example of a rake task that cleans out sessions that are
some many weeks old:

You can call the rake task in a cron job, but clearing them out every
five minutes seems a little extreme. I wondering if you are after
something to timeout the session if it hasn't been modified for the
last five minutes. Then you are after something like SessionTimeout:


Or if you are using MySQL 5.1 as a backend for your session you have
the ability to schedule a task that can delete the sessions that are
5min or older.