module Mongoid::QueryCache
A cache of database queries on a per-request basis.
@since 4.0.0
Public Instance Methods
cache() { || ... }
click to toggle source
Execute the block while using the query cache.
@example Execute with the cache.
QueryCache.cache { collection.find }
@return [ Object ] The result of the block.
@since 4.0.0
# File lib/mongoid/query_cache.rb, line 65 def cache enabled = QueryCache.enabled? QueryCache.enabled = true yield ensure QueryCache.enabled = enabled end
cache_table()
click to toggle source
Get the cached queries.
@example Get the cached queries from the current thread.
QueryCache.cache_table
@return [ Hash ] The hash of cached queries.
@since 4.0.0
# File lib/mongoid/query_cache.rb, line 17 def cache_table Thread.current["[mongoid]:query_cache"] ||= {} end
clear_cache()
click to toggle source
Clear the query cache.
@example Clear the cache.
QueryCache.clear_cache
@return [ nil ] Always nil.
@since 4.0.0
# File lib/mongoid/query_cache.rb, line 29 def clear_cache Thread.current["[mongoid]:query_cache"] = nil end
enabled=(value)
click to toggle source
Set whether the cache is enabled.
@example Set if the cache is enabled.
QueryCache.enabled = true
@param [ true, false ] value The enabled value.
@since 4.0.0
# File lib/mongoid/query_cache.rb, line 41 def enabled=(value) Thread.current["[mongoid]:query_cache:enabled"] = value end
enabled?()
click to toggle source
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.
@since 4.0.0
# File lib/mongoid/query_cache.rb, line 53 def enabled? !!Thread.current["[mongoid]:query_cache:enabled"] end