Module: Mongoid::QueryCache
- Defined in:
- lib/mongoid/query_cache.rb
Overview
A cache of database queries on a per-request basis.
Defined Under Namespace
Modules: Base, Cacheable, Collection, Query Classes: CachedCursor, Middleware
Class Method Summary collapse
-
.cache ⇒ Object
Execute the block while using the query cache.
-
.cache_table ⇒ Hash
Get the cached queries.
-
.clear_cache ⇒ nil
Clear the query cache.
-
.enabled=(value) ⇒ Object
Set whether the cache is enabled.
-
.enabled? ⇒ true, false
Is the query cache enabled on the current thread?.
Class Method Details
.cache ⇒ Object
Execute the block while using the query cache.
66 67 68 69 70 71 72 |
# File 'lib/mongoid/query_cache.rb', line 66 def cache enabled = QueryCache.enabled? QueryCache.enabled = true yield ensure QueryCache.enabled = enabled end |
.cache_table ⇒ Hash
Get the cached queries.
18 19 20 |
# File 'lib/mongoid/query_cache.rb', line 18 def cache_table Thread.current["[mongoid]:query_cache"] ||= {} end |
.clear_cache ⇒ nil
Clear the query cache.
30 31 32 |
# File 'lib/mongoid/query_cache.rb', line 30 def clear_cache Thread.current["[mongoid]:query_cache"] = nil end |
.enabled=(value) ⇒ Object
Set whether the cache is enabled.
42 43 44 |
# File 'lib/mongoid/query_cache.rb', line 42 def enabled=(value) Thread.current["[mongoid]:query_cache:enabled"] = value end |
.enabled? ⇒ true, false
Is the query cache enabled on the current thread?
54 55 56 |
# File 'lib/mongoid/query_cache.rb', line 54 def enabled? !!Thread.current["[mongoid]:query_cache:enabled"] end |