Module: ActiveSupport::Cache::Strategy::LocalCache
- Included in:
- FileStore, MemCacheStore, NullStore, RedisCacheStore
- 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
-
#cleanup(**options) ⇒ Object
:nodoc:.
-
#clear(**options) ⇒ Object
:nodoc:.
-
#decrement(name, amount = 1, **options) ⇒ Object
:nodoc:.
-
#increment(name, amount = 1, **options) ⇒ 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) ⇒ Object
:nodoc:
101 102 103 104 105 |
# File 'lib/active_support/cache/strategy/local_cache.rb', line 101 def cleanup(**) # :nodoc: return super unless cache = local_cache cache.clear super end |
#clear(**options) ⇒ Object
:nodoc:
95 96 97 98 99 |
# File 'lib/active_support/cache/strategy/local_cache.rb', line 95 def clear(**) # :nodoc: return super unless cache = local_cache cache.clear() super end |
#decrement(name, amount = 1, **options) ⇒ Object
:nodoc:
114 115 116 117 118 119 |
# File 'lib/active_support/cache/strategy/local_cache.rb', line 114 def decrement(name, amount = 1, **) # :nodoc: return super unless local_cache value = bypass_local_cache { super } write_cache_value(name, value, **) value end |
#increment(name, amount = 1, **options) ⇒ Object
:nodoc:
107 108 109 110 111 112 |
# File 'lib/active_support/cache/strategy/local_cache.rb', line 107 def increment(name, amount = 1, **) # :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.
89 90 91 92 93 |
# File 'lib/active_support/cache/strategy/local_cache.rb', line 89 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.
83 84 85 |
# File 'lib/active_support/cache/strategy/local_cache.rb', line 83 def with_local_cache use_temporary_local_cache(LocalStore.new) { yield } end |