Hi, it seems like session files never get erased? I''ve made a small monkeypath for environment.rb to clean up old session every time a new session is created. Do you know of any nicer place to put this code? Without having to add cron-jobs or other os-dependent solutions? Does it exists any trigger or similar that get executed every N''th request to the rails application that instead can be used to cleanup the session directory? Have a nice day, Tobias class PStore def initialize_with_cleanup(session) unless File::exist?(session) expire_time = Time.now - 3600 # 1 hour Dir["#{ActionController::Base.session_options[:tmpdir]}/ #{ActionController::Base.session_options[:prefix]}*"].each do |sess| (File.delete(sess) if File.ctime(sess) < expire_time) rescue nil end end initialize_without_cleanup(session) end alias_method_chain :initialize, :cleanup end --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 2 Oct 2007, at 16:05, Tobias Nurmiranta wrote:> > Hi, it seems like session files never get erased? I''ve made a small > monkeypath for environment.rb to clean up old session every time a new > session is created. Do you know of any nicer place to put this code? > Without having to add cron-jobs or other os-dependent solutions? >Isn''t this going to hurt performance by scouring the sessions folder and looking at the modification time of every file there, for each and every request ?> Does it exists any trigger or similar that get executed every N''th > request to the rails application that instead can be used to cleanup > the session directory? >not that I know of. cookie based sessions are nice in that you don''t need to worry about this sort of stuff. Fred> Have a nice day, > Tobias > > > class PStore > def initialize_with_cleanup(session) > unless File::exist?(session) > expire_time = Time.now - 3600 # 1 hour > Dir["#{ActionController::Base.session_options[:tmpdir]}/ > #{ActionController::Base.session_options[:prefix]}*"].each do |sess| > (File.delete(sess) if File.ctime(sess) < expire_time) rescue > nil > end > end > initialize_without_cleanup(session) > end > alias_method_chain :initialize, :cleanup > end > > > >--~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
You can create a very simple cron job using find and looking at the creation or modification time of the session files to remove them. Tobias Nurmiranta wrote:> Hi, it seems like session files never get erased? I''ve made a small > monkeypath for environment.rb to clean up old session every time a new > session is created. Do you know of any nicer place to put this code? > Without having to add cron-jobs or other os-dependent solutions? > > Does it exists any trigger or similar that get executed every N''th > request to the rails application that instead can be used to cleanup > the session directory? > > Have a nice day, > Tobias > > > class PStore > def initialize_with_cleanup(session) > unless File::exist?(session) > expire_time = Time.now - 3600 # 1 hour > Dir["#{ActionController::Base.session_options[:tmpdir]}/ > #{ActionController::Base.session_options[:prefix]}*"].each do |sess| > (File.delete(sess) if File.ctime(sess) < expire_time) rescue > nil > end > end > initialize_without_cleanup(session) > end > alias_method_chain :initialize, :cleanup > end > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Oct 2, 5:12 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 2 Oct 2007, at 16:05, Tobias Nurmiranta wrote: > > > > > Hi, it seems like session files never get erased? I''ve made a small > > monkeypath for environment.rb to clean up old session every time a new > > session is created. Do you know of any nicer place to put this code? > > Without having to add cron-jobs or other os-dependent solutions? > > Isn''t this going to hurt performance by scouring the sessions folder > and looking at the modification time of every file there, for each > and every request ?Its not every request, only when a new session is created. Which can be quite often as well.> > Does it exists any trigger or similar that get executed every N''th > > request to the rails application that instead can be used to cleanup > > the session directory? > > not that I know of. > > cookie based sessions are nice in that you don''t need to worry about > this sort of stuff.But this is only available in rails edge?> > Fred > > > Have a nice day, > > Tobias > > > class PStore > > def initialize_with_cleanup(session) > > unless File::exist?(session) > > expire_time = Time.now - 3600 # 1 hour > > Dir["#{ActionController::Base.session_options[:tmpdir]}/ > > #{ActionController::Base.session_options[:prefix]}*"].each do |sess| > > (File.delete(sess) if File.ctime(sess) < expire_time) rescue > > nil > > end > > end > > initialize_without_cleanup(session) > > end > > alias_method_chain :initialize, :cleanup > > end--~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi Tobias I think there is a Rake Task to clear the tmp directory rake tmp:sessions:clear I saw it in Aptana RadRails RakeTasks Tab HTH On Oct 2, 11:05 pm, Tobias Nurmiranta <nurmira...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, it seems like session files never get erased? I''ve made a small > monkeypath for environment.rb to clean up old session every time a new > session is created. Do you know of any nicer place to put this code? > Without having to add cron-jobs or other os-dependent solutions? > > Does it exists any trigger or similar that get executed every N''th > request to the rails application that instead can be used to cleanup > the session directory? > > Have a nice day, > Tobias > > class PStore > def initialize_with_cleanup(session) > unless File::exist?(session) > expire_time = Time.now - 3600 # 1 hour > Dir["#{ActionController::Base.session_options[:tmpdir]}/ > #{ActionController::Base.session_options[:prefix]}*"].each do |sess| > (File.delete(sess) if File.ctime(sess) < expire_time) rescue > nil > end > end > initialize_without_cleanup(session) > end > alias_method_chain :initialize, :cleanup > end--~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi> I think there is a Rake Task to clear the tmp directory > > rake tmp:sessions:clearIt will simply remove all session files. If you need to delete expired files only you can check this task: http://www.taknado.com/2007/7/25/rake-task-to-clear-expired-session-files --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Tobias Nurmiranta wrote:> Hi, it seems like session files never get erased? I''ve made a small > monkeypath for environment.rb to clean up old session every time a new > session is created. Do you know of any nicer place to put this code? > Without having to add cron-jobs or other os-dependent solutions? > > Does it exists any trigger or similar that get executed every N''th > request to the rails application that instead can be used to cleanup > the session directory?Beware, the file based session store was never meant for production. Use ActiveRecordStore or one of the other alternatives. -- Cheers, - Jacob Atzen --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---