Class: ActiveRecord::ConnectionAdapters::StatementPool
- Inherits:
-
Object
- Object
- ActiveRecord::ConnectionAdapters::StatementPool
show all
- Includes:
- Enumerable
- Defined in:
- lib/active_record/connection_adapters/statement_pool.rb
Overview
Constant Summary
collapse
- DEFAULT_STATEMENT_LIMIT =
1000
Instance Method Summary
collapse
Constructor Details
#initialize(statement_limit = nil) ⇒ StatementPool
Returns a new instance of StatementPool.
10
11
12
13
|
# File 'lib/active_record/connection_adapters/statement_pool.rb', line 10
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
23
24
25
|
# File 'lib/active_record/connection_adapters/statement_pool.rb', line 23
def [](key)
cache[key]
end
|
#[]=(sql, stmt) ⇒ Object
31
32
33
34
35
36
|
# File 'lib/active_record/connection_adapters/statement_pool.rb', line 31
def []=(sql, stmt)
while @statement_limit <= cache.size
dealloc(cache.shift.last)
end
cache[sql] = stmt
end
|
#clear ⇒ Object
38
39
40
41
42
43
|
# File 'lib/active_record/connection_adapters/statement_pool.rb', line 38
def clear
cache.each_value do |stmt|
dealloc stmt
end
cache.clear
end
|
#delete(key) ⇒ Object
52
53
54
55
56
57
|
# File 'lib/active_record/connection_adapters/statement_pool.rb', line 52
def delete(key)
if stmt = cache.delete(key)
dealloc(stmt)
end
stmt
end
|
#each(&block) ⇒ Object
15
16
17
|
# File 'lib/active_record/connection_adapters/statement_pool.rb', line 15
def each(&block)
cache.each(&block)
end
|
#key?(key) ⇒ Boolean
19
20
21
|
# File 'lib/active_record/connection_adapters/statement_pool.rb', line 19
def key?(key)
cache.key?(key)
end
|
#length ⇒ Object
27
28
29
|
# File 'lib/active_record/connection_adapters/statement_pool.rb', line 27
def length
cache.length
end
|
#reset ⇒ Object
Clear the pool without deallocating; this is only safe when we know the server has independently deallocated all statements (e.g. due to a reconnect, or a DISCARD ALL)
48
49
50
|
# File 'lib/active_record/connection_adapters/statement_pool.rb', line 48
def reset
cache.clear
end
|