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).
- #supports_statement_cache? ⇒ Boolean
Instance Method Details
#clear_cache! ⇒ Object
Clears the prepared statements cache.
32 33 34 |
# File 'lib/arjdbc/abstract/statement_cache.rb', line 32 def clear_cache! @statements.clear end |
#delete_cached_statement(sql) ⇒ Object
36 37 38 |
# File 'lib/arjdbc/abstract/statement_cache.rb', line 36 def delete_cached_statement(sql) @statements.delete(sql_key(sql)) end |
#fetch_cached_statement(sql) ⇒ Object
40 41 42 |
# File 'lib/arjdbc/abstract/statement_cache.rb', line 40 def fetch_cached_statement(sql) @statements[sql_key(sql)] ||= @connection.prepare_statement(sql) end |
#initialize(*args) ⇒ Object
(connection, logger, config)
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/arjdbc/abstract/statement_cache.rb', line 20 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 |
#supports_statement_cache? ⇒ Boolean
44 45 46 |
# File 'lib/arjdbc/abstract/statement_cache.rb', line 44 def supports_statement_cache? @jdbc_statement_cache_enabled end |