module Mongoid::QueryCache::Cacheable
Module to include in objects which need to wrap caching behaviour around them.
@since 4.0.0
Private Instance Methods
instrument(key, &block)
click to toggle source
# File lib/mongoid/query_cache.rb, line 145 def instrument(key, &block) ActiveSupport::Notifications.instrument("query_cache.mongoid", key: key, &block) end
with_cache(context = :cursor) { || ... }
click to toggle source
# File lib/mongoid/query_cache.rb, line 133 def with_cache(context = :cursor, &block) return yield unless QueryCache.enabled? return yield if system_collection? key = cache_key.push(context) if QueryCache.cache_table.has_key?(key) instrument(key) { QueryCache.cache_table[key] } else QueryCache.cache_table[key] = yield end end