Module: ActiveSupport::Cache::Strategy::LocalCache

Included in:
FileStore, MemCacheStore, NullStore
Defined in:
lib/active_support/cache/strategy/local_cache.rb,
lib/active_support/cache/strategy/local_cache_middleware.rb

Overview

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.

Defined Under Namespace

Classes: LocalCacheRegistry, LocalStore, Middleware

Instance Method Summary collapse

Instance Method Details

#cleanup(options = nil) ⇒ Object

:nodoc:



88
89
90
91
92
# File 'lib/active_support/cache/strategy/local_cache.rb', line 88

def cleanup(options = nil) # :nodoc:
  return super unless cache = local_cache
  cache.clear(options)
  super
end

#clear(options = nil) ⇒ Object

:nodoc:



82
83
84
85
86
# File 'lib/active_support/cache/strategy/local_cache.rb', line 82

def clear(options = nil) # :nodoc:
  return super unless cache = local_cache
  cache.clear(options)
  super
end

#decrement(name, amount = 1, options = nil) ⇒ Object

:nodoc:



101
102
103
104
105
106
# File 'lib/active_support/cache/strategy/local_cache.rb', line 101

def decrement(name, amount = 1, options = nil) # :nodoc:
  return super unless local_cache
  value = bypass_local_cache { super }
  write_cache_value(name, value, options)
  value
end

#increment(name, amount = 1, options = nil) ⇒ Object

:nodoc:



94
95
96
97
98
99
# File 'lib/active_support/cache/strategy/local_cache.rb', line 94

def increment(name, amount = 1, options = nil) # :nodoc:
  return super unless local_cache
  value = bypass_local_cache { super }
  write_cache_value(name, value, options)
  value
end

#middlewareObject

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



76
77
78
79
80
# File 'lib/active_support/cache/strategy/local_cache.rb', line 76

def middleware
  @middleware ||= Middleware.new(
    "ActiveSupport::Cache::Strategy::LocalCache",
    local_cache_key)
end

#with_local_cacheObject

Use a local cache for the duration of block.



70
71
72
# File 'lib/active_support/cache/strategy/local_cache.rb', line 70

def with_local_cache
  use_temporary_local_cache(LocalStore.new) { yield }
end