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.
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 |
# File 'lib/mongoid/query_cache.rb', line 205 def each if system_collection? || !QueryCache.enabled? super else key = cache_key cursor = QueryCache.cache_table[key] unless cursor server = read.select_server(cluster) cursor = CachedCursor.new(view, send_initial_query(server), server) QueryCache.cache_table[key] = cursor end cursor.each do |doc| yield doc end if block_given? cursor end end |