Sha256: fb43f27cd7bc7d0291953da217e49e12dd50e5bc3fbf0c3d79dfaa6c9eaf5097

Contents?: true

Size: 1.04 KB

Versions: 20

Compression:

Stored size: 1.04 KB

Contents

module ActiveRecord
  module ConnectionAdapters
    class StatementPool # :nodoc:
      include Enumerable

      DEFAULT_STATEMENT_LIMIT = 1000

      def initialize(statement_limit = nil)
        @cache = Hash.new { |h, pid| h[pid] = {} }
        @statement_limit = statement_limit || DEFAULT_STATEMENT_LIMIT
      end

      def each(&block)
        cache.each(&block)
      end

      def key?(key)
        cache.key?(key)
      end

      def [](key)
        cache[key]
      end

      def length
        cache.length
      end

      def []=(sql, stmt)
        while @statement_limit <= cache.size
          dealloc(cache.shift.last)
        end
        cache[sql] = stmt
      end

      def clear
        cache.each_value do |stmt|
          dealloc stmt
        end
        cache.clear
      end

      def delete(key)
        dealloc cache[key]
        cache.delete(key)
      end

      private

        def cache
          @cache[Process.pid]
        end

        def dealloc(stmt)
          raise NotImplementedError
        end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
activerecord-5.1.7 lib/active_record/connection_adapters/statement_pool.rb
activerecord-5.1.7.rc1 lib/active_record/connection_adapters/statement_pool.rb
activerecord-5.1.6.2 lib/active_record/connection_adapters/statement_pool.rb
activerecord-5.1.6.1 lib/active_record/connection_adapters/statement_pool.rb
activerecord-5.1.6 lib/active_record/connection_adapters/statement_pool.rb
activerecord-5.1.5 lib/active_record/connection_adapters/statement_pool.rb
activerecord-5.1.5.rc1 lib/active_record/connection_adapters/statement_pool.rb
activerecord-5.1.4 lib/active_record/connection_adapters/statement_pool.rb
activerecord-5.1.4.rc1 lib/active_record/connection_adapters/statement_pool.rb
activerecord-5.1.3 lib/active_record/connection_adapters/statement_pool.rb
activerecord-5.1.3.rc3 lib/active_record/connection_adapters/statement_pool.rb
activerecord-5.1.3.rc2 lib/active_record/connection_adapters/statement_pool.rb
activerecord-5.1.3.rc1 lib/active_record/connection_adapters/statement_pool.rb
activerecord-5.1.2 lib/active_record/connection_adapters/statement_pool.rb
activerecord-5.1.2.rc1 lib/active_record/connection_adapters/statement_pool.rb
activerecord-5.1.1 lib/active_record/connection_adapters/statement_pool.rb
activerecord-5.1.0 lib/active_record/connection_adapters/statement_pool.rb
activerecord-5.1.0.rc2 lib/active_record/connection_adapters/statement_pool.rb
activerecord-5.1.0.rc1 lib/active_record/connection_adapters/statement_pool.rb
activerecord-5.1.0.beta1 lib/active_record/connection_adapters/statement_pool.rb