Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport #8074 to 3-2-stable. Use query cache/uncache, when using not only database.yml but also DATABASE_URL. #8205

Merged
merged 1 commit into from Nov 13, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions activerecord/CHANGELOG.md
@@ -1,5 +1,10 @@
## Rails 3.2.10 (unreleased)

* Use query cache/uncache when using ENV["DATABASE_URL"].
Fixes #6951. [Backport #8074]

*kennyj*

* Do not create useless database transaction when building `has_one` association. [Backport #8154]

Example:
Expand Down
12 changes: 6 additions & 6 deletions activerecord/lib/active_record/query_cache.rb
Expand Up @@ -6,19 +6,19 @@ class QueryCache
module ClassMethods
# Enable the query cache within the block if Active Record is configured.
def cache(&block)
if ActiveRecord::Base.configurations.blank?
yield
else
if ActiveRecord::Base.connected?
connection.cache(&block)
else
yield
end
end

# Disable the query cache within the block if Active Record is configured.
def uncached(&block)
if ActiveRecord::Base.configurations.blank?
yield
else
if ActiveRecord::Base.connected?
connection.uncached(&block)
else
yield
end
end
end
Expand Down
11 changes: 11 additions & 0 deletions activerecord/test/cases/query_cache_test.rb
Expand Up @@ -173,6 +173,17 @@ def test_cache_is_ignored_for_locked_relations
assert_queries(2) { task.lock!; task.lock! }
end
end

def test_cache_is_available_when_connection_is_connected
conf = ActiveRecord::Base.configurations

ActiveRecord::Base.configurations = {}
Task.cache do
assert_queries(1) { Task.find(1); Task.find(1) }
end
ensure
ActiveRecord::Base.configurations = conf
end
end

class QueryCacheExpiryTest < ActiveRecord::TestCase
Expand Down