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 @deprecated This class is only used with driver versions 2.13 and lower.
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 187 def each if @cached_documents @cached_documents.each do |doc| yield doc end 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 205 def inspect "#<Mongoid::QueryCache::CachedCursor:0x#{object_id} @view=#{@view.inspect}>" end
Private Instance Methods
process(result)
click to toggle source
Calls superclass method
# File lib/mongoid/query_cache.rb, line 211 def process(result) documents = super if @cursor_id.zero? && !@after_first_batch @cached_documents ||= [] @cached_documents.concat(documents) end @after_first_batch = true documents end