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

Instance Method Details

#cleanup(**options) ⇒ Object

:nodoc:



104
105
106
107
108
# File 'lib/active_support/cache/strategy/local_cache.rb', line 104

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

#clear(**options) ⇒ Object

:nodoc:



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

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

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

:nodoc:



123
124
125
126
127
128
# File 'lib/active_support/cache/strategy/local_cache.rb', line 123

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

#delete_matched(matcher, options = nil) ⇒ Object

:nodoc:



110
111
112
113
114
# File 'lib/active_support/cache/strategy/local_cache.rb', line 110

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

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

:nodoc:



116
117
118
119
120
121
# File 'lib/active_support/cache/strategy/local_cache.rb', line 116

def increment(name, amount = 1, **options) # :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.



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

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.



86
87
88
# File 'lib/active_support/cache/strategy/local_cache.rb', line 86

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