Sha256: 8d6fde5da8e805727e50aacc6a2962d9f914e58c1791a8520fd5058a9b335eac

Contents?: true

Size: 871 Bytes

Versions: 170

Compression:

Stored size: 871 Bytes

Contents

# encoding: utf-8
module Mongoid #:nodoc:

  # Adds support for caching queries at the class level.
  module Extras
    extend ActiveSupport::Concern

    included do
      class_attribute :cached
      self.cached = false
    end

    module ClassMethods #:nodoc

      # 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.
      #
      # @example Cache all reads for the class.
      #   class Person
      #     include Mongoid::Document
      #     cache
      #   end
      def cache
        self.cached = true
      end
    end
  end
end

Version data entries

170 entries across 78 versions & 4 rubygems

Version Path
mongoid-2.4.5 lib/mongoid/extras.rb
mongoid-2.4.4 lib/mongoid/extras.rb
mongoid-2.4.3 lib/mongoid/extras.rb
mongoid-2.4.2 lib/mongoid/extras.rb
mongoid-2.4.1 lib/mongoid/extras.rb
mongoid-2.4.0 lib/mongoid/extras.rb
mongoid-2.3.4 lib/mongoid/extras.rb
mongoid-2.3.3 lib/mongoid/extras.rb
mongoid-2.3.2 lib/mongoid/extras.rb
mongoid-2.3.1 lib/mongoid/extras.rb