class Mongoid::QueryCache::CachedCursor
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
Public Instance Methods
each() { |doc| ... }
click to toggle source
We iterate over the cached documents if they exist already in the cursor otherwise proceed as normal.
@example Iterate over the documents.
cursor.each do |doc| # ... end
@since 5.0.0
Calls superclass method
# File lib/mongoid/query_cache.rb, line 138 def each if @cached_documents @cached_documents.each{ |doc| yield doc } else super end end
inspect()
click to toggle source
Get a human-readable string representation of Cursor
.
@example Inspect the cursor.
cursor.inspect
@return [ String ] A string representation of a Cursor
instance.
@since 2.0.0
# File lib/mongoid/query_cache.rb, line 154 def inspect "#<Mongoid::QueryCache::CachedCursor:0x#{object_id} @view=#{@view.inspect}>" end
Private Instance Methods
process(result)
click to toggle source
# File lib/mongoid/query_cache.rb, line 160 def process(result) @remaining -= result.returned_count if limited? @cursor_id = result.cursor_id @coll_name ||= result.namespace.sub("#{database.name}.", '') if result.namespace documents = result.documents (@cached_documents ||= []).concat(documents) documents end