diff options
author | Eileen Uchitelle <eileencodes@gmail.com> | 2019-01-29 13:18:58 -0500 |
---|---|---|
committer | Eileen Uchitelle <eileencodes@gmail.com> | 2019-02-01 16:05:25 -0500 |
commit | 183c0eb472a33e4f1f2cd9502f238d4b6027f887 (patch) | |
tree | 4bb649a49d8ee0dd1dc037d13b0c55bad7f5bae2 /activerecord/lib/active_record/connection_handling.rb | |
parent | 79bc9e81c3d47be6336223be39cb3bcaeddc0a39 (diff) | |
download | rails-183c0eb472a33e4f1f2cd9502f238d4b6027f887.tar.gz rails-183c0eb472a33e4f1f2cd9502f238d4b6027f887.tar.bz2 rails-183c0eb472a33e4f1f2cd9502f238d4b6027f887.zip |
Invalidate query cache for all connections in the current thread
This change ensures that all query cahces are cleared across all
connections per handler for the current thread so if you write on one
connection the read will have the query cache cleared.
Diffstat (limited to 'activerecord/lib/active_record/connection_handling.rb')
-rw-r--r-- | activerecord/lib/active_record/connection_handling.rb | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/connection_handling.rb b/activerecord/lib/active_record/connection_handling.rb index 558cdeccf2..53069cd899 100644 --- a/activerecord/lib/active_record/connection_handling.rb +++ b/activerecord/lib/active_record/connection_handling.rb @@ -176,6 +176,15 @@ module ActiveRecord config_hash end + # Clears the query cache for all connections associated with the current thread. + def clear_query_caches_for_current_thread + ActiveRecord::Base.connection_handlers.each_value do |handler| + handler.connection_pool_list.each do |pool| + pool.connection.clear_query_cache if pool.active_connection? + end + end + end + # Returns the connection currently associated with the class. This can # also be used to "borrow" the connection to do database work unrelated # to any of the specific Active Records. |