Method: Mongoid::Criterion::Optional#cache

Defined in:
lib/mongoid/criterion/optional.rb

#cacheCriteria

Tells the criteria that the cursor that gets returned needs to be cached. This is so multiple iterations don’t hit the database multiple times, however this is not advisable when working with large data sets as the entire results will get stored in memory.

Examples:

Flag the criteria as cached.

criteria.cache

Returns:



33
34
35
# File 'lib/mongoid/criterion/optional.rb', line 33

def cache
  clone.tap { |crit| crit.options.merge!(:cache => true) }
end