diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2007-02-19 23:51:25 +0000 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2007-02-19 23:51:25 +0000 |
commit | 772e02dd62989dbe08cc774a5ada2ae6430033ad (patch) | |
tree | 9046f79705f202c8128efe5b9e8d4b9494c40be8 /actionpack/lib | |
parent | 9e4c8b88584ba09c46abcd484969da6244416946 (diff) | |
download | rails-772e02dd62989dbe08cc774a5ada2ae6430033ad.tar.gz rails-772e02dd62989dbe08cc774a5ada2ae6430033ad.tar.bz2 rails-772e02dd62989dbe08cc774a5ada2ae6430033ad.zip |
Factor out unique id generator. Expose cgi to session store.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6174 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/lib')
-rw-r--r-- | actionpack/lib/action_controller/cgi_ext/session_performance_fix.rb | 38 |
1 files changed, 25 insertions, 13 deletions
diff --git a/actionpack/lib/action_controller/cgi_ext/session_performance_fix.rb b/actionpack/lib/action_controller/cgi_ext/session_performance_fix.rb index 7305167860..6f9a09da6d 100644 --- a/actionpack/lib/action_controller/cgi_ext/session_performance_fix.rb +++ b/actionpack/lib/action_controller/cgi_ext/session_performance_fix.rb @@ -3,28 +3,40 @@ # when serving requests from a long-lived process. # # http://railsexpress.de/blog/articles/2005/11/22/speeding-up-the-creation-of-new-sessions +# +# Also expose the CGI instance to session stores. require 'cgi/session' require 'digest/md5' class CGI class Session #:nodoc: + # Generate an MD5 hash including the time, a random number, the process id, + # and a constant string. This is used to generate session ids but may be + # reused elsewhere. + def self.generate_unique_id(constant = 'foobar') + md5 = Digest::MD5.new + now = Time.now + md5 << now.to_s + md5 << String(now.usec) + md5 << String(rand(0)) + md5 << String($$) + md5 << constant + md5.hexdigest + end + + # Make the CGI instance available to session stores. + attr_reader :cgi + alias_method :initialize_without_cgi_reader, :initialize + def initialize(cgi, options = {}) + @cgi = cgi + initialize_without_cgi_reader(cgi, options) + end + private # Create a new session id. - # - # The session id is an MD5 hash based upon the time, - # a random number, and a constant string. This routine - # is used internally for automatically generated - # session ids. def create_new_id - md5 = Digest::MD5::new - now = Time::now - md5.update(now.to_s) - md5.update(String(now.usec)) - md5.update(String(rand(0))) - md5.update(String($$)) - md5.update('foobar') @new_session = true - md5.hexdigest + self.class.generate_unique_id end end end |