Module: Mongoid::QueryCache::View
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/mongoid/query_cache.rb
Overview
Contains enhancements to the Mongo::Collection::View in order to get a cached cursor or a regular cursor on iteration.
Instance Method Summary collapse
-
#each ⇒ Object
Override the default enumeration to handle if the cursor can be cached or not.
Instance Method Details
#each ⇒ Object
Override the default enumeration to handle if the cursor can be cached or not.
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 |
# File 'lib/mongoid/query_cache.rb', line 220 def each if system_collection? || !QueryCache.enabled? super else unless cursor = cached_cursor read_with_retry do server = server_selector.select_server(cluster) cursor = CachedCursor.new(view, send_initial_query(server), server) QueryCache.cache_table[cache_key] = cursor end end cursor.each do |doc| yield doc end if block_given? cursor end end |