Sha256: 5d8961d8069a041588a9805bd1c029937421d708a2ff33211f6f860ae53e9c13

Contents?: true

Size: 860 Bytes

Versions: 76

Compression:

Stored size: 860 Bytes

Contents

module ActionSubscriber
  module Middleware
    module ActiveRecord
      class QueryCache
        CURRENT_CONNECTION = "_action_subscriber_query_cache_current_connection".freeze

        def initialize(app)
          @app = app
        end

        def call(env)
          connection = ::Thread.current[CURRENT_CONNECTION] = ::ActiveRecord::Base.connection
          enabled = connection.query_cache_enabled
          connection.enable_query_cache!

          @app.call(env)
        ensure
          restore_query_cache_settings(enabled)
        end

        private

        def restore_query_cache_settings(enabled)
          ::Thread.current[CURRENT_CONNECTION].clear_query_cache
          ::Thread.current[CURRENT_CONNECTION].disable_query_cache! unless enabled
          ::Thread.current[CURRENT_CONNECTION] = nil
        end
      end
    end
  end
end

Version data entries

76 entries across 76 versions & 1 rubygems

Version Path
action_subscriber-5.3.3-java lib/action_subscriber/middleware/active_record/query_cache.rb
action_subscriber-5.3.3 lib/action_subscriber/middleware/active_record/query_cache.rb
action_subscriber-5.3.2-java lib/action_subscriber/middleware/active_record/query_cache.rb
action_subscriber-5.3.2 lib/action_subscriber/middleware/active_record/query_cache.rb
action_subscriber-5.3.1-java lib/action_subscriber/middleware/active_record/query_cache.rb
action_subscriber-5.3.1 lib/action_subscriber/middleware/active_record/query_cache.rb
action_subscriber-5.3.1.pre-java lib/action_subscriber/middleware/active_record/query_cache.rb
action_subscriber-5.3.1.pre lib/action_subscriber/middleware/active_record/query_cache.rb
action_subscriber-5.3.0-java lib/action_subscriber/middleware/active_record/query_cache.rb
action_subscriber-5.3.0 lib/action_subscriber/middleware/active_record/query_cache.rb
action_subscriber-5.2.4-java lib/action_subscriber/middleware/active_record/query_cache.rb
action_subscriber-5.2.4 lib/action_subscriber/middleware/active_record/query_cache.rb
action_subscriber-5.2.3-java lib/action_subscriber/middleware/active_record/query_cache.rb
action_subscriber-5.2.3 lib/action_subscriber/middleware/active_record/query_cache.rb
action_subscriber-5.2.2-java lib/action_subscriber/middleware/active_record/query_cache.rb
action_subscriber-5.2.2 lib/action_subscriber/middleware/active_record/query_cache.rb
action_subscriber-5.2.1-java lib/action_subscriber/middleware/active_record/query_cache.rb
action_subscriber-5.2.1 lib/action_subscriber/middleware/active_record/query_cache.rb
action_subscriber-5.2.0-java lib/action_subscriber/middleware/active_record/query_cache.rb
action_subscriber-5.2.0 lib/action_subscriber/middleware/active_record/query_cache.rb