Skip to content

Commit

Permalink
Currently, we clear query_cache in cache block finish, even if we may…
Browse files Browse the repository at this point in the history
… already have cache true.

This commit takes into account the last cache_enabled value, before clearing query_cache.
  • Loading branch information
vipulnsward committed Dec 3, 2013
1 parent b6f189e commit 1ed81e8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
5 changes: 5 additions & 0 deletions activerecord/CHANGELOG.md
@@ -1,3 +1,8 @@
* Fix `QueryCache` to work with nested blocks, so that it will only clear the existing cache
after leaving the outer block instead of clearing it right after the inner block is finished.

*Vipul A M*

* The ERB in fixture files is no longer evaluated in the context of the main * The ERB in fixture files is no longer evaluated in the context of the main
object. Helper methods used by multiple fixtures should be defined on the object. Helper methods used by multiple fixtures should be defined on the
class object returned by `ActiveRecord::FixtureSet.context_class`. class object returned by `ActiveRecord::FixtureSet.context_class`.
Expand Down
Expand Up @@ -31,8 +31,8 @@ def cache
old, @query_cache_enabled = @query_cache_enabled, true old, @query_cache_enabled = @query_cache_enabled, true
yield yield
ensure ensure
clear_query_cache
@query_cache_enabled = old @query_cache_enabled = old
clear_query_cache unless @query_cache_enabled
end end


def enable_query_cache! def enable_query_cache!
Expand Down
9 changes: 9 additions & 0 deletions activerecord/test/cases/query_cache_test.rb
Expand Up @@ -134,6 +134,15 @@ def test_find_queries_with_cache_multi_record
end end
end end


def test_find_queries_with_multi_cache_blocks
Task.cache do
Task.cache do
assert_queries(2) { Task.find(1); Task.find(2) }
end
assert_queries(0) { Task.find(1); Task.find(1); Task.find(2) }
end
end

def test_count_queries_with_cache def test_count_queries_with_cache
Task.cache do Task.cache do
assert_queries(1) { Task.count; Task.count } assert_queries(1) { Task.count; Task.count }
Expand Down

0 comments on commit 1ed81e8

Please sign in to comment.