aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/base.rb
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2005-12-04 05:56:49 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2005-12-04 05:56:49 +0000
commitdc64887f21d319bb3beb9a71dcc487641ebf8c1f (patch)
treef1cae8b32771df569d249c542f78a06bed1fda49 /activerecord/lib/active_record/base.rb
parent1dfa0bd3728a6c3b8fc037dd6b524044513f5a1d (diff)
downloadrails-dc64887f21d319bb3beb9a71dcc487641ebf8c1f.tar.gz
rails-dc64887f21d319bb3beb9a71dcc487641ebf8c1f.tar.bz2
rails-dc64887f21d319bb3beb9a71dcc487641ebf8c1f.zip
Connection cache to speed up retrieve_connection and get rid of dirty connection marking. References #428.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3218 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib/active_record/base.rb')
-rwxr-xr-xactiverecord/lib/active_record/base.rb8
1 files changed, 7 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb
index 4232b18450..d8cdf225d6 100755
--- a/activerecord/lib/active_record/base.rb
+++ b/activerecord/lib/active_record/base.rb
@@ -243,11 +243,17 @@ module ActiveRecord #:nodoc:
# on to any new database connections made and which can be retrieved on both a class and instance level by calling +logger+.
cattr_accessor :logger
+ @@connection_cache = Hash.new { |h, k| h[k] = Hash.new }
+
# Returns the connection currently associated with the class. This can
# also be used to "borrow" the connection to do database work unrelated
# to any of the specific Active Records.
def self.connection
- retrieve_connection
+ @@connection_cache[Thread.current.object_id][name] ||= retrieve_connection
+ end
+
+ def self.clear_connection_cache!
+ @@connection_cache.clear
end
# Returns the connection currently associated with the class. This can