diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2007-02-22 08:14:47 +0000 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2007-02-22 08:14:47 +0000 |
commit | f425bba9cf6c6a7268a906cb888a8a3af4f9abcb (patch) | |
tree | e33733f1b8a6b5f5a23cf1b180b416c0b4e237d7 /activerecord | |
parent | c8f7860d5034c2ab92c1a9fc3bc61cd5d80ee146 (diff) | |
download | rails-f425bba9cf6c6a7268a906cb888a8a3af4f9abcb.tar.gz rails-f425bba9cf6c6a7268a906cb888a8a3af4f9abcb.tar.bz2 rails-f425bba9cf6c6a7268a906cb888a8a3af4f9abcb.zip |
Use the query cache iff Active Record is configured.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6202 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/query_cache.rb | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/activerecord/lib/active_record/query_cache.rb b/activerecord/lib/active_record/query_cache.rb index e29c86d935..9296c5b81a 100644 --- a/activerecord/lib/active_record/query_cache.rb +++ b/activerecord/lib/active_record/query_cache.rb @@ -87,14 +87,22 @@ module ActiveRecord def query_cache=(cache) query_caches[self] = cache end - - def cache - self.query_cache = QueryCache.new(connection_without_query_cache) - yield - ensure - self.query_cache = nil - end - + + # Use a query cache within the given block. + def cache + # Don't cache if Active Record is not configured. + if ActiveRecord::Base.configurations.blank? + yield + else + begin + self.query_cache = QueryCache.new(connection_without_query_cache) + yield + ensure + self.query_cache = nil + end + end + end + def connection query_cache || connection_without_query_cache end |