Class: ActiveRecord::Turntable::QueryCache

Inherits:
QueryCache
  • Object
show all
Defined in:
lib/active_record/turntable/query_cache.rb

Class Method Summary collapse

Class Method Details

.complete(enabled) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/active_record/turntable/query_cache.rb', line 19

def self.complete(enabled)
  klasses = ActiveRecord::Base.turntable_connections.values
  klasses.each do |k|
    k.connection.clear_query_cache
    k.connection.disable_query_cache! unless enabled
  end
end

.install_executor_hooks(executor = ActiveSupport::Executor) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/active_record/turntable/query_cache.rb', line 27

def self.install_executor_hooks(executor = ActiveSupport::Executor)
  executor.register_hook(self)

  executor.to_complete do
    klasses = ActiveRecord::Base.turntable_connection_classes
    klasses.each do |k|
      unless k.connected? && k.connection.transaction_open?
        k.clear_active_connections!
      end
    end
  end
end

.runObject



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/active_record/turntable/query_cache.rb', line 7

def self.run
  klasses = ActiveRecord::Base.turntable_connections.values
  enables = klasses.map do |k|
    enabled = k.connection.query_cache_enabled
    k.connection.enable_query_cache!

    enabled
  end

  enables.all?
end