That will be processed for every request, which isn't really
necessary. It probably won't add THAT much overhead, but if you have a
high volume site you'd want to offload the session clearing into
something else.

* you could make a rake task that deletes sessions older than a
certain offset, and call that from cron
* put it into your authentication code, rather than a before_filter,
that way it'll only run when someone logs in
* your idea of a simple class that runs from cron, using script/
runner. Seems like a valid approach.
* use a scheduling gem/plugin.

On Sep 18, 7:40 am, Greg Donald <[email protected]> wrote:
> On Thu, Sep 17, 2009 at 7:46 PM, TRBNGR <[email protected]> wrote:
>
> > Ok, I tried searching for the answer to this but couldn't find a
> > thread about it, so here goes...
>
> > I'm using sessions that I am storing in the database, is there an
> > accepted rails way of deleting out the old sessions?
>
> > Unless I hear a better idea, I was going to write a simple class and
> > call it from a cronjob to delete sessions that have been inactive
> > after a specified period of time.
>
> class ApplicationController < ActionController::Base
>
>   before_filter :clean
>
>   def clean
>     ActiveRecord::Base.connection.execute( "
>       DELETE FROM sessions
>       WHERE NOW() - updated_at > 3600
>     " ) if rand( 1000 ) % 10 == 0
>   end
>
> end
>
> --
> Greg Donaldhttp://destiney.com/
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to