From 7104122cc3fca4939d77a6780910cd98ff02fab0 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 27 Oct 2010 14:05:40 -0700 Subject: making query cache work with prepared statements --- .../connection_adapters/abstract/query_cache.rb | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'activerecord/lib/active_record/connection_adapters/abstract') diff --git a/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb b/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb index 0ee61d0b6f..cbc09dfc3b 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb @@ -49,23 +49,24 @@ module ActiveRecord @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 -- cgit v1.2.3