Module: Mongoid::QueryCache
- Defined in:
- lib/mongoid/query_cache.rb,
lib/mongoid/query_cache/railtie.rb,
lib/mongoid/query_cache/version.rb
Overview
A cache of database queries on a per-request basis.
Defined Under Namespace
Modules: Base, Cacheable, Collection, Query Classes: CachedCursor, Middleware, Railtie
Constant Summary collapse
- VERSION =
'0.0.1'
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.
62 63 64 65 66 67 68 |
# File 'lib/mongoid/query_cache.rb', line 62 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.
29 30 31 |
# File 'lib/mongoid/query_cache.rb', line 29 def clear_cache Thread.current["[mongoid]:query_cache"] = nil end |
.enabled=(value) ⇒ Object
Set whether the cache is enabled.
40 41 42 |
# File 'lib/mongoid/query_cache.rb', line 40 def enabled=(value) Thread.current["[mongoid]:query_cache:enabled"] = value end |
.enabled? ⇒ true, false
Is the query cache enabled on the current thread?
51 52 53 |
# File 'lib/mongoid/query_cache.rb', line 51 def enabled? !!Thread.current["[mongoid]:query_cache:enabled"] end |