Module: Mongoid::QueryCache::View Deprecated
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/mongoid/query_cache.rb
Overview
Deprecated.
This module is only used with driver versions 2.13 and lower.
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.
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 |
# File 'lib/mongoid/query_cache.rb', line 240 def each if system_collection? || !QueryCache.enabled? || (respond_to?(:write?, true) && write?) super else @cursor = nil unless @cursor = cached_cursor session = client.send(:get_session, @options) read_with_retry(session, server_selector) do |server| result = send_initial_query(server, session) if result.cursor_id == 0 || result.cursor_id.nil? @cursor = CachedCursor.new(view, result, server, session: session) QueryCache.cache_table[cache_key] = @cursor else @cursor = Mongo::Cursor.new(view, result, server, session: session) end end end if block_given? if limit @cursor.to_a[0...limit].each do |doc| yield doc end else @cursor.each do |doc| yield doc end end else @cursor.to_enum end end end |