Sha256: c30019fa581f4149e3fe23f8861da6e945f4a30255e43253af708c8684f12388

Contents?: true

Size: 948 Bytes

Versions: 42

Compression:

Stored size: 948 Bytes

Contents

# frozen_string_literal: true

module Switchman
  module ActiveRecord
    module QueryCache
      private

      def cache_sql(sql, name, binds)
        # have to include the shard id in the cache key because of switching dbs on the same connection
        sql = "#{shard.id}::#{sql}"
        @lock.synchronize do
          result =
            if query_cache[sql].key?(binds)
              args = {
                sql: sql,
                binds: binds,
                name: name,
                connection_id: object_id,
                cached: true,
                type_casted_binds: -> { type_casted_binds(binds) }
              }
              ::ActiveSupport::Notifications.instrument(
                'sql.active_record',
                args
              )
              query_cache[sql][binds]
            else
              query_cache[sql][binds] = yield
            end
          result.dup
        end
      end
    end
  end
end

Version data entries

42 entries across 42 versions & 1 rubygems

Version Path
switchman-3.4.2 lib/switchman/active_record/query_cache.rb
switchman-3.4.1 lib/switchman/active_record/query_cache.rb
switchman-3.4.0 lib/switchman/active_record/query_cache.rb
switchman-3.3.7 lib/switchman/active_record/query_cache.rb
switchman-3.3.6 lib/switchman/active_record/query_cache.rb
switchman-3.3.5 lib/switchman/active_record/query_cache.rb
switchman-3.3.4 lib/switchman/active_record/query_cache.rb
switchman-3.3.3 lib/switchman/active_record/query_cache.rb
switchman-3.3.2 lib/switchman/active_record/query_cache.rb
switchman-3.3.1 lib/switchman/active_record/query_cache.rb
switchman-3.3.0 lib/switchman/active_record/query_cache.rb
switchman-3.2.1 lib/switchman/active_record/query_cache.rb
switchman-3.2.0 lib/switchman/active_record/query_cache.rb
switchman-3.1.3 lib/switchman/active_record/query_cache.rb
switchman-3.1.2 lib/switchman/active_record/query_cache.rb
switchman-3.1.1 lib/switchman/active_record/query_cache.rb
switchman-3.1.0 lib/switchman/active_record/query_cache.rb
switchman-3.0.24 lib/switchman/active_record/query_cache.rb
switchman-3.0.23 lib/switchman/active_record/query_cache.rb
switchman-3.0.22 lib/switchman/active_record/query_cache.rb