Class: Mongoid::QueryCache::CachedCursor

Inherits:
Mongo::Cursor
  • Object
show all
Defined in:
lib/mongoid/query_cache.rb

Overview

A Cursor that attempts to load documents from memory first before hitting the database if the same query has already been executed.

Since:

  • 5.0.0

Instance Method Summary collapse

Instance Method Details

#eachObject

We iterate over the cached documents if they exist already in the cursor otherwise proceed as normal.

Examples:

Iterate over the documents.

cursor.each do |doc|
  # ...
end

Since:

  • 5.0.0



125
126
127
128
129
130
131
# File 'lib/mongoid/query_cache.rb', line 125

def each
  if @cached_documents
    @cached_documents.each{ |doc| yield doc }
  else
    super
  end
end

#inspectString

Get a human-readable string representation of Cursor.

Examples:

Inspect the cursor.

cursor.inspect

Returns:

  • (String)

    A string representation of a Cursor instance.

Since:

  • 2.0.0



141
142
143
# File 'lib/mongoid/query_cache.rb', line 141

def inspect
  "#<Mongoid::QueryCache::CachedCursor:0x#{object_id} @view=#{@view.inspect}>"
end