Module: Mongoid::QueryCache

Defined in:
build/mongoid-master/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.



46
47
48
# File 'build/mongoid-master/lib/mongoid/query_cache.rb', line 46

def cache(&block)
  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
# File 'build/mongoid-master/lib/mongoid/query_cache.rb', line 16

def clear_cache
  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.



26
27
28
# File 'build/mongoid-master/lib/mongoid/query_cache.rb', line 26

def enabled=(value)
  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.



36
37
38
# File 'build/mongoid-master/lib/mongoid/query_cache.rb', line 36

def enabled?
  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.



56
57
58
# File 'build/mongoid-master/lib/mongoid/query_cache.rb', line 56

def uncached(&block)
  Mongo::QueryCache.uncached(&block)
end