Module: ArJdbc::Abstract::StatementCache

Defined Under Namespace

Classes: StatementPool

Instance Method Summary collapse

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(cached_statement_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[cached_statement_key(sql)] ||= @connection.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 = config[: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

Returns:

  • (Boolean)


44
45
46
# File 'lib/arjdbc/abstract/statement_cache.rb', line 44

def supports_statement_cache?
  @jdbc_statement_cache_enabled
end