Class: ActiveRecord::ConnectionAdapters::MysqlAdapter::StatementPool

Inherits:
StatementPool
  • Object
show all
Defined in:
lib/active_record/connection_adapters/mysql_adapter.rb

Instance Method Summary collapse

Constructor Details

#initialize(connection, max = 1000) ⇒ StatementPool

Returns a new instance of StatementPool.



190
191
192
193
# File 'lib/active_record/connection_adapters/mysql_adapter.rb', line 190

def initialize(connection, max = 1000)
  super
  @cache = Hash.new { |h,pid| h[pid] = {} }
end

Instance Method Details

#[](key) ⇒ Object



197
# File 'lib/active_record/connection_adapters/mysql_adapter.rb', line 197

def [](key);      cache[key]; end

#[]=(sql, key) ⇒ Object



201
202
203
204
205
206
# File 'lib/active_record/connection_adapters/mysql_adapter.rb', line 201

def []=(sql, key)
  while @max <= cache.size
    cache.shift.last[:stmt].close
  end
  cache[sql] = key
end

#clearObject



208
209
210
211
212
213
# File 'lib/active_record/connection_adapters/mysql_adapter.rb', line 208

def clear
  cache.values.each do |hash|
    hash[:stmt].close
  end
  cache.clear
end

#delete(key) ⇒ Object



199
# File 'lib/active_record/connection_adapters/mysql_adapter.rb', line 199

def delete(key);  cache.delete(key); end

#each(&block) ⇒ Object



195
# File 'lib/active_record/connection_adapters/mysql_adapter.rb', line 195

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

#key?(key) ⇒ Boolean

Returns:

  • (Boolean)


196
# File 'lib/active_record/connection_adapters/mysql_adapter.rb', line 196

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

#lengthObject



198
# File 'lib/active_record/connection_adapters/mysql_adapter.rb', line 198

def length;       cache.length; end