Skip to content

Commit 308b705

Browse files
authored
Merge pull request rails#55007 from rails/fxn/hide-executor-hooks
Make the executor hooks in AR::QueryCache private
2 parents c593a74 + 04358ef commit 308b705

File tree

1 file changed

+22
-15
lines changed

1 file changed

+22
-15
lines changed

activerecord/lib/active_record/query_cache.rb

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
module ActiveRecord
44
# = Active Record Query Cache
55
class QueryCache
6+
# ActiveRecord::Base extends this module, so these methods are available in models.
67
module ClassMethods
78
# Enable the query cache within the block if Active Record is configured.
89
# If it's not, it will execute the given block.
@@ -20,11 +21,15 @@ def cache(&block)
2021
end
2122
end
2223

23-
# Disable the query cache within the block if Active Record is configured.
24-
# If it's not, it will execute the given block.
24+
# Runs the block with the query cache disabled.
25+
#
26+
# If the query cache was enabled before the block was executed, it is
27+
# enabled again after it.
2528
#
26-
# Set <tt>dirties: false</tt> to prevent query caches on all connections from being cleared by write operations.
27-
# (By default, write operations dirty all connections' query caches in case they are replicas whose cache would now be outdated.)
29+
# Set <tt>dirties: false</tt> to prevent query caches on all connections
30+
# from being cleared by write operations. (By default, write operations
31+
# dirty all connections' query caches in case they are replicas whose
32+
# cache would now be outdated.)
2833
def uncached(dirties: true, &block)
2934
if connected? || !configurations.empty?
3035
connection_pool.disable_query_cache(dirties: dirties, &block)
@@ -34,22 +39,24 @@ def uncached(dirties: true, &block)
3439
end
3540
end
3641

37-
def self.run
38-
ActiveRecord::Base.connection_handler.each_connection_pool.reject(&:query_cache_enabled).each do |pool|
39-
next if pool.db_config&.query_cache == false
40-
pool.enable_query_cache!
42+
module ExecutorHooks # :nodoc:
43+
def self.run
44+
ActiveRecord::Base.connection_handler.each_connection_pool.reject(&:query_cache_enabled).each do |pool|
45+
next if pool.db_config&.query_cache == false
46+
pool.enable_query_cache!
47+
end
4148
end
42-
end
4349

44-
def self.complete(pools)
45-
pools.each do |pool|
46-
pool.disable_query_cache!
47-
pool.clear_query_cache
50+
def self.complete(pools)
51+
pools.each do |pool|
52+
pool.disable_query_cache!
53+
pool.clear_query_cache
54+
end
4855
end
4956
end
5057

51-
def self.install_executor_hooks(executor = ActiveSupport::Executor)
52-
executor.register_hook(self)
58+
def self.install_executor_hooks(executor = ActiveSupport::Executor) # :nodoc:
59+
executor.register_hook(ExecutorHooks)
5360
end
5461
end
5562
end

0 commit comments

Comments
 (0)