Sha256: c0ee86f0149cd2e07e9006efa07b4935b639ef5d07a1dac1b5c7f1fdb9c0b473

Contents?: true

Size: 798 Bytes

Versions: 11

Compression:

Stored size: 798 Bytes

Contents

module Protobuf
  module ActiveRecord
    module Middleware
      class QueryCache
        def initialize(app)
          @app = app
        end

        def call(env)
          enabled = ::ActiveRecord::Base.connection.query_cache_enabled
          connection_id = ::ActiveRecord::Base.connection_id
          ::ActiveRecord::Base.connection.enable_query_cache!

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

      private

        def restore_query_cache_settings(connection_id, enabled)
          ::ActiveRecord::Base.connection_id = connection_id
          ::ActiveRecord::Base.connection.clear_query_cache
          ::ActiveRecord::Base.connection.disable_query_cache! unless enabled
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
protobuf-activerecord-3.3.4 lib/protobuf/active_record/middleware/query_cache.rb
protobuf-activerecord-3.3.3 lib/protobuf/active_record/middleware/query_cache.rb
protobuf-activerecord-3.3.2 lib/protobuf/active_record/middleware/query_cache.rb
protobuf-activerecord-3.3.1 lib/protobuf/active_record/middleware/query_cache.rb
protobuf-activerecord-3.3.0 lib/protobuf/active_record/middleware/query_cache.rb
protobuf-activerecord-3.2.2 lib/protobuf/active_record/middleware/query_cache.rb
protobuf-activerecord-3.2.1 lib/protobuf/active_record/middleware/query_cache.rb
protobuf-activerecord-3.2.0 lib/protobuf/active_record/middleware/query_cache.rb
protobuf-activerecord-3.1.1 lib/protobuf/active_record/middleware/query_cache.rb
protobuf-activerecord-3.1.0 lib/protobuf/active_record/middleware/query_cache.rb
protobuf-activerecord-3.1.0.rc1 lib/protobuf/active_record/middleware/query_cache.rb