Module: ArJdbc::Abstract::StatementCache
- Included in:
- ActiveRecord::ConnectionAdapters::Mysql2Adapter, ActiveRecord::ConnectionAdapters::PostgreSQLAdapter, ActiveRecord::ConnectionAdapters::SQLite3Adapter
- Defined in:
- lib/arjdbc/abstract/statement_cache.rb
Defined Under Namespace
Classes: StatementPool
Instance Method Summary collapse
-
#clear_cache! ⇒ Object
Clears the prepared statements cache.
- #delete_cached_statement(sql) ⇒ Object
- #fetch_cached_statement(sql) ⇒ Object
-
#initialize(*args) ⇒ Object
(connection, logger, config).
Instance Method Details
#clear_cache! ⇒ Object
Clears the prepared statements cache.
34 35 36 |
# File 'lib/arjdbc/abstract/statement_cache.rb', line 34 def clear_cache! @statements.clear end |
#delete_cached_statement(sql) ⇒ Object
38 39 40 |
# File 'lib/arjdbc/abstract/statement_cache.rb', line 38 def delete_cached_statement(sql) @statements.delete(sql_key(sql)) end |
#fetch_cached_statement(sql) ⇒ Object
42 43 44 |
# File 'lib/arjdbc/abstract/statement_cache.rb', line 42 def fetch_cached_statement(sql) @statements[sql_key(sql)] ||= @connection.prepare_statement(sql) end |
#initialize(*args) ⇒ Object
(connection, logger, config)
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/arjdbc/abstract/statement_cache.rb', line 22 def initialize(*args) # (connection, logger, config) super # Only say we support the statement cache if we are using prepared statements # and have a max number of statements defined statement_limit = self.class.type_cast_config_to_integer(config[:statement_limit]) @jdbc_statement_cache_enabled = prepared_statements && (statement_limit.nil? || statement_limit > 0) @statements = StatementPool.new(statement_limit) # AR (5.0) expects this to be stored as @statements end |