aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2014-11-27 14:40:19 -0200
committerRafael Mendonça França <rafaelmfranca@gmail.com>2014-11-27 14:40:19 -0200
commit8fc7eb5f21e42f1bc484c496a6431c284b9ee805 (patch)
treecdb961c72fdb97ebe20ffab382d3c8a7442c7fe4
parent07f4bd5b60d062bda58a45ca5f832a0a6bcdc713 (diff)
downloadrails-8fc7eb5f21e42f1bc484c496a6431c284b9ee805.tar.gz
rails-8fc7eb5f21e42f1bc484c496a6431c284b9ee805.tar.bz2
rails-8fc7eb5f21e42f1bc484c496a6431c284b9ee805.zip
Update the StatementCache documentation
-rw-r--r--activerecord/lib/active_record/statement_cache.rb19
1 files changed, 15 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/statement_cache.rb b/activerecord/lib/active_record/statement_cache.rb
index 767c7561cf..c68990bf99 100644
--- a/activerecord/lib/active_record/statement_cache.rb
+++ b/activerecord/lib/active_record/statement_cache.rb
@@ -1,18 +1,29 @@
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:
+ # Initializing the cache is done by passing the statement in the create block:
#
- # cache = ActiveRecord::StatementCache.new do
- # Book.where(name: "my book").limit(100)
+ # 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
+ # cache.execute([], Book, Book.connection)
#
# 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.
+ #
+ # 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
+ #
+ # And pass the bind values as the first argument of +execute+ call.
+ #
+ # cache.execute(["my book"], Book, Book.connection)
class StatementCache # :nodoc:
class Substitute; end # :nodoc: