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 create block:
cache = StatementCache.create(Book.connection) do |params| Book.where(name: "my book").where("author_id > 3") end
The cached statement is executed by using the execute method:
cache.execute(, Book, Book.connection)
If you want to cache the statement without the values you can use the bind method of the block parameter.
cache = StatementCache.create(Book.connection) do |params| Book.where(name: params.bind) end
cache.execute(["my book"], Book, Book.connection)