Module: ActiveSupport::Cache::Strategy::LocalCache
- Defined in:
- lib/active_support/cache/strategy/local_cache.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: 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:
91 92 93 94 |
# File 'lib/active_support/cache/strategy/local_cache.rb', line 91 def cleanup( = nil) # :nodoc: local_cache.clear() if local_cache super end |
#clear(options = nil) ⇒ Object
:nodoc:
86 87 88 89 |
# File 'lib/active_support/cache/strategy/local_cache.rb', line 86 def clear( = nil) # :nodoc: local_cache.clear() if local_cache super end |
#decrement(name, amount = 1, options = nil) ⇒ Object
:nodoc:
110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/active_support/cache/strategy/local_cache.rb', line 110 def decrement(name, amount = 1, = nil) # :nodoc: value = bypass_local_cache{super} if local_cache local_cache.mute do if value local_cache.write(name, value, ) else local_cache.delete(name, ) end end end value end |
#increment(name, amount = 1, options = nil) ⇒ Object
:nodoc:
96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/active_support/cache/strategy/local_cache.rb', line 96 def increment(name, amount = 1, = nil) # :nodoc: value = bypass_local_cache{super} if local_cache local_cache.mute do if value local_cache.write(name, value, ) else local_cache.delete(name, ) end end end value end |
#middleware ⇒ Object
Middleware class can be inserted as a Rack handler to be local cache for the duration of request.
80 81 82 83 84 |
# 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 ⇒ Object
Use a local cache for the duration of block.
43 44 45 46 47 48 49 50 51 |
# 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 |