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
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.
> 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.
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.