module ActiveSupport::Cache::Strategy::LocalCache

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.

Public Instance Methods

middleware() click to toggle source

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 80
def middleware
  @middleware ||= Middleware.new(
    "ActiveSupport::Cache::Strategy::LocalCache",
    thread_local_key)
end
with_local_cache() { || ... } click to toggle source

Use a local cache for the duration of block.

# File lib/active_support/cache/strategy/local_cache.rb, line 43
def with_local_cache
  save_val = Thread.current[thread_local_key]
  begin
    Thread.current[thread_local_key] = LocalStore.new
    yield
  ensure
    Thread.current[thread_local_key] = save_val
  end
end

Private Instance Methods

bypass_local_cache() { || ... } click to toggle source
# File lib/active_support/cache/strategy/local_cache.rb, line 157
def bypass_local_cache
  save_cache = Thread.current[thread_local_key]
  begin
    Thread.current[thread_local_key] = nil
    yield
  ensure
    Thread.current[thread_local_key] = save_cache
  end
end
local_cache() click to toggle source
# File lib/active_support/cache/strategy/local_cache.rb, line 153
def local_cache
  Thread.current[thread_local_key]
end
thread_local_key() click to toggle source
# File lib/active_support/cache/strategy/local_cache.rb, line 149
def thread_local_key
  @thread_local_key ||= "#{self.class.name.underscore}_local_cache_#{object_id}".gsub(/[\/-]/, '_').to_sym
end