Sha256: f5ede8d190f315ff3d003236280a2f8d0e777b0479ce23b564e39f58b4e71161

Contents?: true

Size: 926 Bytes

Versions: 4

Compression:

Stored size: 926 Bytes

Contents

module ActiveRecord
  module ConnectionAdapters
    class StatementPool
      include Enumerable

      def initialize(max = 1000)
        @cache = Hash.new { |h,pid| h[pid] = {} }
        @max = max
      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 @max <= 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

4 entries across 4 versions & 1 rubygems

Version Path
activerecord-5.0.0.beta3 lib/active_record/connection_adapters/statement_pool.rb
activerecord-5.0.0.beta2 lib/active_record/connection_adapters/statement_pool.rb
activerecord-5.0.0.beta1.1 lib/active_record/connection_adapters/statement_pool.rb
activerecord-5.0.0.beta1 lib/active_record/connection_adapters/statement_pool.rb