Class: ActiveRecord::ConnectionAdapters::RedshiftAdapter::StatementPool
- Inherits:
-
ConnectionAdapters::StatementPool
- Object
- ConnectionAdapters::StatementPool
- ActiveRecord::ConnectionAdapters::RedshiftAdapter::StatementPool
- Defined in:
- lib/active_record/connection_adapters/redshift_adapter.rb
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(sql, key) ⇒ Object
- #clear ⇒ Object
- #delete(sql_key) ⇒ Object
- #each(&block) ⇒ Object
-
#initialize(connection, max) ⇒ StatementPool
constructor
A new instance of StatementPool.
- #key?(key) ⇒ Boolean
- #length ⇒ Object
- #next_key ⇒ Object
Constructor Details
#initialize(connection, max) ⇒ StatementPool
Returns a new instance of StatementPool.
173 174 175 176 177 |
# File 'lib/active_record/connection_adapters/redshift_adapter.rb', line 173 def initialize(connection, max) super @counter = 0 @cache = Hash.new { |h,pid| h[pid] = {} } end |
Instance Method Details
#[](key) ⇒ Object
181 |
# File 'lib/active_record/connection_adapters/redshift_adapter.rb', line 181 def [](key); cache[key]; end |
#[]=(sql, key) ⇒ Object
188 189 190 191 192 193 194 |
# File 'lib/active_record/connection_adapters/redshift_adapter.rb', line 188 def []=(sql, key) while @max <= cache.size dealloc(cache.shift.last) end @counter += 1 cache[sql] = key end |
#clear ⇒ Object
196 197 198 199 200 201 |
# File 'lib/active_record/connection_adapters/redshift_adapter.rb', line 196 def clear cache.each_value do |stmt_key| dealloc stmt_key end cache.clear end |
#delete(sql_key) ⇒ Object
203 204 205 206 |
# File 'lib/active_record/connection_adapters/redshift_adapter.rb', line 203 def delete(sql_key) dealloc cache[sql_key] cache.delete sql_key end |
#each(&block) ⇒ Object
179 |
# File 'lib/active_record/connection_adapters/redshift_adapter.rb', line 179 def each(&block); cache.each(&block); end |
#key?(key) ⇒ Boolean
180 |
# File 'lib/active_record/connection_adapters/redshift_adapter.rb', line 180 def key?(key); cache.key?(key); end |
#length ⇒ Object
182 |
# File 'lib/active_record/connection_adapters/redshift_adapter.rb', line 182 def length; cache.length; end |
#next_key ⇒ Object
184 185 186 |
# File 'lib/active_record/connection_adapters/redshift_adapter.rb', line 184 def next_key "a#{@counter + 1}" end |