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

Included in:
MemCacheStore, NullStore, RedisCacheStore
Defined in:
activesupport/lib/active_support/cache/strategy/local_cache.rb,
activesupport/lib/active_support/cache/strategy/local_cache_middleware.rb

Overview

Local Cache Strategy

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

Modules: LocalCacheRegistry Classes: LocalStore, Middleware

Instance Method Summary collapse

Instance Method Details

#cleanup(options = nil) ⇒ Object

:nodoc:



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

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

#clear(options = nil) ⇒ Object

:nodoc:



79
80
81
82
83
# File 'activesupport/lib/active_support/cache/strategy/local_cache.rb', line 79

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

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

:nodoc:



108
109
110
111
112
113
114
115
116
117
# File 'activesupport/lib/active_support/cache/strategy/local_cache.rb', line 108

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

#delete_matched(matcher, options = nil) ⇒ Object

:nodoc:



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

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

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

:nodoc:



97
98
99
100
101
102
103
104
105
106
# File 'activesupport/lib/active_support/cache/strategy/local_cache.rb', line 97

def increment(name, amount = 1, options = nil) # :nodoc:
  return super unless local_cache
  value = bypass_local_cache { super }
  if options
    write_cache_value(name, value, raw: true, **options)
  else
    write_cache_value(name, value, raw: true)
  end
  value
end

#middlewareObject

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



73
74
75
76
77
# File 'activesupport/lib/active_support/cache/strategy/local_cache.rb', line 73

def middleware
  @middleware ||= Middleware.new(
    "ActiveSupport::Cache::Strategy::LocalCache",
    local_cache_key)
end

#with_local_cache(&block) ⇒ Object

Use a local cache for the duration of block.



67
68
69
# File 'activesupport/lib/active_support/cache/strategy/local_cache.rb', line 67

def with_local_cache(&block)
  use_temporary_local_cache(LocalStore.new, &block)
end