Module: Mongoid::Extras::ClassMethods

Defined in:
lib/mongoid/extras.rb

Overview

:nodoc

Instance Method Summary collapse

Instance Method Details

#cacheObject

Sets caching on for this class. This class level configuration will default all queries to cache the results of the first iteration over the cursor into an internal array. This should only be used for queries that return a small number of results or have small documents, as after the first iteration the entire results will be stored in memory.

Examples:

Cache all reads for the class.

class Person
  include Mongoid::Document
  cache
end


38
39
40
# File 'lib/mongoid/extras.rb', line 38

def cache
  self.cached = true
end

#cached?true, false

Determines if the class is cached or not.

Examples:

Are class reads cached?

Document.cached?

Returns:

  • (true, false)

    If the reads are cached.



48
49
50
# File 'lib/mongoid/extras.rb', line 48

def cached?
  !!self.cached
end