Skip to content
Find file
27 lines (24 sloc) 801 Bytes
module ActiveRecord
# 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 = 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.
class StatementCache
def initialize
@relation = yield
raise"Statement cannot be nil") if @relation.nil?
def execute
Jump to Line
Something went wrong with that request. Please try again.