Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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
  • Loading branch information...
commit 772e02dd62989dbe08cc774a5ada2ae6430033ad 1 parent 9e4c8b8
@jeremy jeremy authored
Showing with 25 additions and 13 deletions.
  1. +25 −13 actionpack/lib/action_controller/cgi_ext/session_performance_fix.rb
View
38 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
Please sign in to comment.
Something went wrong with that request. Please try again.