class StatementCache

Ruby on Rails 4.1.16

Since v4.0.13

Available in: v4.0.13 v4.1.16 v6.0.6 v6.1.7.10 v7.0.10 v7.1.6 v7.2.3 v8.0.4 v8.1.2

Statement cache is used to cache a single statement in order to avoid creating the AST again. Initializing the cache is done by passing the statement in the initialization block:

cache = ActiveRecord::StatementCache.new do
  Book.where(name: "my book").limit(100)
end

The cached statement is executed by using the execute method:

cache.execute

The relation returned by the block is cached, and for each execute call the cached relation gets duped. Database is queried when to_a is called on the relation.

Inherits from

Object

Methods (defined here)

Methods (inherited)

From Object (22)

Type at least 2 characters to search.

↑↓ navigate · open · esc close