Skip to Content Skip to Search

Local Cache Strategy

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.

Namespace
Methods
L
M
N
U
W

Instance Public methods

local_cache()

The current local cache.

# File activesupport/lib/active_support/cache/strategy/local_cache.rb, line 82
def local_cache
  LocalCacheRegistry.cache_for(local_cache_key)
end

middleware()

Middleware class can be inserted as a Rack handler to be local cache for the duration of request.

# File activesupport/lib/active_support/cache/strategy/local_cache.rb, line 88
def middleware
  @middleware ||= Middleware.new("ActiveSupport::Cache::Strategy::LocalCache", self)
end

new_local_cache()

Set a new local cache.

# File activesupport/lib/active_support/cache/strategy/local_cache.rb, line 72
def new_local_cache
  LocalCacheRegistry.set_cache_for(local_cache_key, LocalStore.new)
end

unset_local_cache()

Unset the current local cache.

# File activesupport/lib/active_support/cache/strategy/local_cache.rb, line 77
def unset_local_cache
  LocalCacheRegistry.set_cache_for(local_cache_key, nil)
end

with_local_cache(&block)

Use a local cache for the duration of block.

# File activesupport/lib/active_support/cache/strategy/local_cache.rb, line 67
def with_local_cache(&block)
  use_temporary_local_cache(LocalStore.new, &block)
end