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.
8
9
10
11
|
# File '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 '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 '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
|
#clear ⇒ Object
36
37
38
39
40
41
|
# File '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 '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 'lib/active_record/connection_adapters/statement_pool.rb', line 13
def each(&block)
cache.each(&block)
end
|
#key?(key) ⇒ Boolean
17
18
19
|
# File 'lib/active_record/connection_adapters/statement_pool.rb', line 17
def key?(key)
cache.key?(key)
end
|
#length ⇒ Object
25
26
27
|
# File 'lib/active_record/connection_adapters/statement_pool.rb', line 25
def length
cache.length
end
|