Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

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

2 participants

Toshinori Kajihara Rafael Mendonça França
Toshinori Kajihara
Collaborator

This is backport #8074.
I send this PR, because 3.2.9 was released.

Please see #6951 for more details.

/cc @rafaelfranca

Rafael Mendonça França rafaelfranca merged commit 5ed0381 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 13, 2012
  1. Toshinori Kajihara

    Backport #8074 to 3-2-stable. Use query cache/uncache, when using not…

    kennyj authored
    … only database.yml but also DATABASE_URL.
This page is out of date. Refresh to see the latest.
5 activerecord/CHANGELOG.md
View
@@ -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:
12 activerecord/lib/active_record/query_cache.rb
View
@@ -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
11 activerecord/test/cases/query_cache_test.rb
View
@@ -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
Something went wrong with that request. Please try again.