提交 1ed81e85 编写于 作者: V Vipul A M

Currently, we clear query_cache in cache block finish, even if we may already have cache true.

This commit takes into account the last cache_enabled value, before clearing query_cache.
上级 b6f189e2
* 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
object. Helper methods used by multiple fixtures should be defined on the
class object returned by `ActiveRecord::FixtureSet.context_class`.
......
......@@ -31,8 +31,8 @@ def cache
old, @query_cache_enabled = @query_cache_enabled, true
yield
ensure
clear_query_cache
@query_cache_enabled = old
clear_query_cache unless @query_cache_enabled
end
def enable_query_cache!
......
......@@ -134,6 +134,15 @@ def test_find_queries_with_cache_multi_record
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
Task.cache do
assert_queries(1) { Task.count; Task.count }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册