blob: 82e9ef3d3d362f5d84fa031467f5e2cbf9e81273 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
module ActiveRecord
module ConnectionAdapters
class StatementPool
include Enumerable
def initialize(connection, max = 1000)
@cache = Hash.new { |h,pid| h[pid] = {} }
@connection = connection
@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
|