Class: ActiveRecord::ConnectionAdapters::StatementPool

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
activerecord/lib/active_record/connection_adapters/statement_pool.rb

Overview

:nodoc:

Constant Summary collapse

DEFAULT_STATEMENT_LIMIT =
1000

Instance Method Summary collapse

Methods included from Enumerable

#as_json, #exclude?, #index_by, #many?, #pluck, #sum, #without

Constructor Details

#initialize(statement_limit = nil) ⇒ StatementPool

Returns a new instance of StatementPool.


8
9
10
11
# File 'activerecord/lib/active_record/connection_adapters/statement_pool.rb', line 8

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

Instance Method Details

#[](key) ⇒ Object


21
22
23
# File 'activerecord/lib/active_record/connection_adapters/statement_pool.rb', line 21

def [](key)
  cache[key]
end

#[]=(sql, stmt) ⇒ Object


29
30
31
32
33
34
# File 'activerecord/lib/active_record/connection_adapters/statement_pool.rb', line 29

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

#clearObject


36
37
38
39
40
41
# File 'activerecord/lib/active_record/connection_adapters/statement_pool.rb', line 36

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

#delete(key) ⇒ Object


43
44
45
46
# File 'activerecord/lib/active_record/connection_adapters/statement_pool.rb', line 43

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

#each(&block) ⇒ Object


13
14
15
# File 'activerecord/lib/active_record/connection_adapters/statement_pool.rb', line 13

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

#key?(key) ⇒ Boolean

Returns:

  • (Boolean)

17
18
19
# File 'activerecord/lib/active_record/connection_adapters/statement_pool.rb', line 17

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

#lengthObject


25
26
27
# File 'activerecord/lib/active_record/connection_adapters/statement_pool.rb', line 25

def length
  cache.length
end