提交 7104122c 编写于 作者: A Aaron Patterson

making query cache work with prepared statements

上级 47ceb135
......@@ -49,23 +49,24 @@ def clear_query_cache
@query_cache.clear
end
def select_all(*args)
def select_all(sql, name = nil, binds = [])
if @query_cache_enabled
cache_sql(args.first) { super }
cache_sql(sql, binds) { super }
else
super
end
end
private
def cache_sql(sql)
def cache_sql(sql, binds)
key = [sql, binds]
result =
if @query_cache.has_key?(sql)
if @query_cache.has_key?(key)
ActiveSupport::Notifications.instrument("sql.active_record",
:sql => sql, :name => "CACHE", :connection_id => self.object_id)
@query_cache[sql]
@query_cache[key]
else
@query_cache[sql] = yield
@query_cache[key] = yield
end
if Array === result
......
......@@ -22,6 +22,12 @@ def test_find_queries_with_cache
end
end
def test_find_queries_with_cache
Task.cache do
assert_queries(2) { 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.
先完成此消息的编辑!
想要评论请 注册