Module: ActiveSupport::Cache::Strategy::LocalCache
- Included in:
- FileStore, MemCacheStore, NullStore
- Defined in:
- activesupport/lib/active_support/cache/strategy/local_cache.rb,
activesupport/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
-
#cleanup(options = nil) ⇒ Object
:nodoc:.
-
#clear(options = nil) ⇒ Object
:nodoc:.
-
#decrement(name, amount = 1, options = nil) ⇒ Object
:nodoc:.
-
#increment(name, amount = 1, options = nil) ⇒ Object
:nodoc:.
-
#middleware ⇒ Object
Middleware class can be inserted as a Rack handler to be local cache for the duration of request.
-
#with_local_cache ⇒ Object
Use a local cache for the duration of block.
Instance Method Details
#cleanup(options = nil) ⇒ Object
:nodoc:
90 91 92 93 94 |
# File 'activesupport/lib/active_support/cache/strategy/local_cache.rb', line 90 def cleanup( = nil) # :nodoc: return super unless cache = local_cache cache.clear super end |
#clear(options = nil) ⇒ Object
:nodoc:
84 85 86 87 88 |
# File 'activesupport/lib/active_support/cache/strategy/local_cache.rb', line 84 def clear( = nil) # :nodoc: return super unless cache = local_cache cache.clear() super end |
#decrement(name, amount = 1, options = nil) ⇒ Object
:nodoc:
103 104 105 106 107 108 |
# File 'activesupport/lib/active_support/cache/strategy/local_cache.rb', line 103 def decrement(name, amount = 1, = nil) # :nodoc: return super unless local_cache value = bypass_local_cache { super } write_cache_value(name, value, ) value end |
#increment(name, amount = 1, options = nil) ⇒ Object
:nodoc:
96 97 98 99 100 101 |
# File 'activesupport/lib/active_support/cache/strategy/local_cache.rb', line 96 def increment(name, amount = 1, = nil) # :nodoc: return super unless local_cache value = bypass_local_cache { super } write_cache_value(name, value, ) value end |
#middleware ⇒ Object
Middleware class can be inserted as a Rack handler to be local cache for the duration of request.
78 79 80 81 82 |
# File 'activesupport/lib/active_support/cache/strategy/local_cache.rb', line 78 def middleware @middleware ||= Middleware.new( "ActiveSupport::Cache::Strategy::LocalCache", local_cache_key) end |
#with_local_cache ⇒ Object
Use a local cache for the duration of block.
72 73 74 |
# File 'activesupport/lib/active_support/cache/strategy/local_cache.rb', line 72 def with_local_cache use_temporary_local_cache(LocalStore.new) { yield } end |