Sha256: c7dfa03f2c1a91e48fa426d4649315f08728bddaa198b8ee60b13324f410a03a

Contents?: true

Size: 1.52 KB

Versions: 9

Compression:

Stored size: 1.52 KB

Contents

# frozen_string_literal: true

module Mongoid

  # A cache of database queries on a per-request basis.
  module QueryCache

    class << self

      # Clear the query cache.
      #
      # @example Clear the cache.
      #   QueryCache.clear_cache
      #
      # @return [ nil ] Always nil.
      def clear_cache
        Mongo::QueryCache.clear
      end

      # Set whether the cache is enabled.
      #
      # @example Set if the cache is enabled.
      #   QueryCache.enabled = true
      #
      # @param [ true | false ] value The enabled value.
      def enabled=(value)
        Mongo::QueryCache.enabled = value
      end

      # Is the query cache enabled on the current thread?
      #
      # @example Is the query cache enabled?
      #   QueryCache.enabled?
      #
      # @return [ true | false ] If the cache is enabled.
      def enabled?
        Mongo::QueryCache.enabled?
      end

      # Execute the block while using the query cache.
      #
      # @example Execute with the cache.
      #   QueryCache.cache { collection.find }
      #
      # @return [ Object ] The result of the block.
      def cache(&block)
        Mongo::QueryCache.cache(&block)
      end

      # Execute the block with the query cache disabled.
      #
      # @example Execute without the cache.
      #   QueryCache.uncached { collection.find }
      #
      # @return [ Object ] The result of the block.
      def uncached(&block)
        Mongo::QueryCache.uncached(&block)
      end
    end

    Middleware = Mongo::QueryCache::Middleware
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
mongoid-8.0.10 lib/mongoid/query_cache.rb
mongoid-8.0.9 lib/mongoid/query_cache.rb
mongoid-8.0.8 lib/mongoid/query_cache.rb
mongoid-8.0.7 lib/mongoid/query_cache.rb
mongoid-8.0.6 lib/mongoid/query_cache.rb
mongoid-8.0.5 lib/mongoid/query_cache.rb
mongoid-8.0.4 lib/mongoid/query_cache.rb
mongoid-8.0.3 lib/mongoid/query_cache.rb
mongoid-8.0.2 lib/mongoid/query_cache.rb