diff options
author | Matthew Draper <matthew@trebex.net> | 2016-11-06 02:19:57 -0500 |
---|---|---|
committer | Matthew Draper <matthew@trebex.net> | 2016-11-06 02:19:57 -0500 |
commit | 3c785bdceed4bdf67708197aa687ced6728d77f3 (patch) | |
tree | a49f06ed4b0cd57e4d81b96e851bfd549a019bc7 /activerecord/lib/active_record/query_cache.rb | |
parent | a6d14df40f81ae766081e6a5d4e5fa428eca3174 (diff) | |
download | rails-3c785bdceed4bdf67708197aa687ced6728d77f3.tar.gz rails-3c785bdceed4bdf67708197aa687ced6728d77f3.tar.bz2 rails-3c785bdceed4bdf67708197aa687ced6728d77f3.zip |
Configure query caching (per thread) on the connection pool
Diffstat (limited to 'activerecord/lib/active_record/query_cache.rb')
-rw-r--r-- | activerecord/lib/active_record/query_cache.rb | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/query_cache.rb b/activerecord/lib/active_record/query_cache.rb index 667bfe96f6..ec246e97bc 100644 --- a/activerecord/lib/active_record/query_cache.rb +++ b/activerecord/lib/active_record/query_cache.rb @@ -24,10 +24,17 @@ module ActiveRecord end def self.run - ActiveRecord::Base.connection.enable_query_cache! + caching_pool = ActiveRecord::Base.connection_pool + caching_was_enabled = caching_pool.query_cache_enabled + + caching_pool.enable_query_cache! + + [caching_pool, caching_was_enabled] end - def self.complete(_) + def self.complete((caching_pool, caching_was_enabled)) + caching_pool.disable_query_cache! unless caching_was_enabled + ActiveRecord::Base.connection_handler.connection_pool_list.each do |pool| pool.release_connection if pool.active_connection? && !pool.connection.transaction_open? end |