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

Defined in:
activesupport/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: LocalCacheRegistry, LocalStore, Middleware

Instance Method Summary collapse

Instance Method Details

#cleanup(options = nil) ⇒ Object

:nodoc:



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

def cleanup(options = nil) # :nodoc:
  local_cache.clear(options) if local_cache
  super
end

#clear(options = nil) ⇒ Object

:nodoc:



97
98
99
100
# File 'activesupport/lib/active_support/cache/strategy/local_cache.rb', line 97

def clear(options = nil) # :nodoc:
  local_cache.clear(options) if local_cache
  super
end

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

:nodoc:



113
114
115
116
117
# File 'activesupport/lib/active_support/cache/strategy/local_cache.rb', line 113

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

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

:nodoc:



107
108
109
110
111
# File 'activesupport/lib/active_support/cache/strategy/local_cache.rb', line 107

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

#middlewareObject

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



91
92
93
94
95
# File 'activesupport/lib/active_support/cache/strategy/local_cache.rb', line 91

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.



60
61
62
# File 'activesupport/lib/active_support/cache/strategy/local_cache.rb', line 60

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