Module: Mongoid::QueryCache

Defined in:
build/mongoid-8.1/lib/mongoid/query_cache.rb

Overview

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

Constant Summary collapse

Middleware =
Mongo::QueryCache::Middleware

Class Method Summary collapse

Class Method Details

.cache(&block) ⇒ Object

Execute the block while using the query cache.

Examples:

Execute with the cache.

QueryCache.cache { collection.find }

Returns:

  • (Object)

    The result of the block.



49
50
51
52
# File 'build/mongoid-8.1/lib/mongoid/query_cache.rb', line 49

def cache(&block)
  Mongoid::Warnings.warn_mongoid_query_cache
  Mongo::QueryCache.cache(&block)
end

.clear_cachenil

Clear the query cache.

Examples:

Clear the cache.

QueryCache.clear_cache

Returns:

  • (nil)

    Always nil.



16
17
18
19
# File 'build/mongoid-8.1/lib/mongoid/query_cache.rb', line 16

def clear_cache
  Mongoid::Warnings.warn_mongoid_query_cache_clear
  Mongo::QueryCache.clear
end

.enabled=(value) ⇒ Object

Set whether the cache is enabled.

Examples:

Set if the cache is enabled.

QueryCache.enabled = true

Parameters:

  • value (true | false)

    The enabled value.



27
28
29
30
# File 'build/mongoid-8.1/lib/mongoid/query_cache.rb', line 27

def enabled=(value)
  Mongoid::Warnings.warn_mongoid_query_cache
  Mongo::QueryCache.enabled = value
end

.enabled?true | false

Is the query cache enabled on the current thread?

Examples:

Is the query cache enabled?

QueryCache.enabled?

Returns:

  • (true | false)

    If the cache is enabled.



38
39
40
41
# File 'build/mongoid-8.1/lib/mongoid/query_cache.rb', line 38

def enabled?
  Mongoid::Warnings.warn_mongoid_query_cache
  Mongo::QueryCache.enabled?
end

.uncached(&block) ⇒ Object

Execute the block with the query cache disabled.

Examples:

Execute without the cache.

QueryCache.uncached { collection.find }

Returns:

  • (Object)

    The result of the block.



60
61
62
63
# File 'build/mongoid-8.1/lib/mongoid/query_cache.rb', line 60

def uncached(&block)
  Mongoid::Warnings.warn_mongoid_query_cache
  Mongo::QueryCache.uncached(&block)
end