Sha256: 7b646a0e1d1a58226b03ff78772a82312c892875ff5a00b3493d39cf39f97dc6

Contents?: true

Size: 801 Bytes

Versions: 72

Compression:

Stored size: 801 Bytes

Contents

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 = 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.
  class StatementCache
    def initialize
      @relation = yield
      raise ArgumentError.new("Statement cannot be nil") if @relation.nil?
    end

    def execute
      @relation.dup.to_a
    end
  end
end

Version data entries

72 entries across 72 versions & 3 rubygems

Version Path
activerecord-4.1.16 lib/active_record/statement_cache.rb
activerecord-4.1.16.rc1 lib/active_record/statement_cache.rb
activerecord-4.1.15 lib/active_record/statement_cache.rb
activerecord-4.1.15.rc1 lib/active_record/statement_cache.rb
activerecord-4.1.14.2 lib/active_record/statement_cache.rb
activerecord-4.1.14.1 lib/active_record/statement_cache.rb
angular-rails4-templates-0.4.1 vendor/ruby/2.1.0/gems/activerecord-4.1.13/lib/active_record/statement_cache.rb
angular-rails4-templates-0.4.0 vendor/ruby/2.1.0/gems/activerecord-4.1.13/lib/active_record/statement_cache.rb
angular-rails4-templates-0.3.0 vendor/ruby/2.1.0/gems/activerecord-4.1.13/lib/active_record/statement_cache.rb
activerecord-4.1.14 lib/active_record/statement_cache.rb
activerecord-4.1.14.rc2 lib/active_record/statement_cache.rb
activerecord-4.1.14.rc1 lib/active_record/statement_cache.rb
activerecord-4.1.13 lib/active_record/statement_cache.rb
activerecord-4.1.13.rc1 lib/active_record/statement_cache.rb
activerecord-4.1.12 lib/active_record/statement_cache.rb
activerecord-4.1.12.rc1 lib/active_record/statement_cache.rb
activerecord-4.1.11 lib/active_record/statement_cache.rb
activerecord-4.1.10 lib/active_record/statement_cache.rb
activerecord-4.1.10.rc4 lib/active_record/statement_cache.rb
activerecord-4.1.10.rc3 lib/active_record/statement_cache.rb