Caches that implement LocalCache will be backed by an in-memory cache for the duration of a block. Repeated calls to the cache for the same key will hit the in-memory cache for faster access.
Middleware class can be inserted as a Rack handler to be local cache for the duration of request.
# File lib/active_support/cache/strategy/local_cache.rb, line 71 def middleware @middleware ||= Middleware.new( "ActiveSupport::Cache::Strategy::LocalCache", local_cache_key) end
Use a local cache for the duration of block.
# File lib/active_support/cache/strategy/local_cache.rb, line 66 def with_local_cache use_temporary_local_cache(LocalStore.new) { yield } end
# File lib/active_support/cache/strategy/local_cache.rb, line 123 def set_cache_value(value, name, amount, options) if local_cache local_cache.mute do if value local_cache.write(name, value, options) else local_cache.delete(name, options) end end end end
# File lib/active_support/cache/strategy/local_cache.rb, line 145 def bypass_local_cache use_temporary_local_cache(nil) { yield } end
# File lib/active_support/cache/strategy/local_cache.rb, line 141 def local_cache LocalCacheRegistry.cache_for(local_cache_key) end
# File lib/active_support/cache/strategy/local_cache.rb, line 137 def local_cache_key @local_cache_key ||= "#{self.class.name.underscore}_local_cache_#{object_id}".gsub(/[\/-]/, '_').to_sym end
# File lib/active_support/cache/strategy/local_cache.rb, line 149 def use_temporary_local_cache(temporary_cache) save_cache = LocalCacheRegistry.cache_for(local_cache_key) begin LocalCacheRegistry.set_cache_for(local_cache_key, temporary_cache) yield ensure LocalCacheRegistry.set_cache_for(local_cache_key, save_cache) end end