require 'active_support/cache/dalli_store'
module ActiveSupport
module Cache
class AtomicDalliStore < DalliStore - ActiveSupport::Cache::AtomicDalliStore has no descriptive comment
def fetch(name, options = nil) -
- ActiveSupport::Cache::AtomicDalliStore#fetch has approx 7 statements
if block_given?
result = read(name, options)
if result.nil? - ActiveSupport::Cache::AtomicDalliStore#fetch performs a nil-check
result = instrument(:generate, name, options) do |payload|
yield
end
write(name, result, options)
else
instrument(:fetch_hit, name, options) { |payload| }
end
result
else
read(name, options)
end
end
def read(name, options = nil) -
super.tap do |result|
if result.present?
return nil if lock!(name, options)
end
end
end
def write(name, value, options = nil) -
expiry = (options && options[:expires_in]) || 0
options[:expires_in] = expiry + 20 unless expiry.zero?
ttl_set(ttl_key(name, options), expiry) && super
end
def delete(name, options = nil) -
ttl_delete(ttl_key(name, options)) && super
end
private
def lock!(name, options) -
- ActiveSupport::Cache::AtomicDalliStore has missing safe method 'lock!'
key = ttl_key(name, options)
ttl_get(key) ? false : ttl_add(key)
end
def ttl_key(name, options) -
"#{namespaced_key(name, options)}.ttl"
end
def ttl_get(key) - ActiveSupport::Cache::AtomicDalliStore#ttl_get has approx 6 statements
with { |c| c.get(key, raw: true) } - ActiveSupport::Cache::AtomicDalliStore#ttl_get has the variable name 'c'
rescue Dalli::DalliError => e - ActiveSupport::Cache::AtomicDalliStore#ttl_get has the variable name 'e'
logger.error("DalliError: #{e.message}") if logger
raise if raise_errors?
nil
end
def ttl_add(key) - ActiveSupport::Cache::AtomicDalliStore#ttl_add has approx 6 statements
with { |c| c.add(key, "", 10, raw: true) } - ActiveSupport::Cache::AtomicDalliStore#ttl_add has the variable name 'c'
rescue Dalli::DalliError => e -
- ActiveSupport::Cache::AtomicDalliStore#ttl_add has the variable name 'e'
logger.error("DalliError: #{e.message}") if logger
raise if raise_errors?
false
end
def ttl_set(key, expiry) - ActiveSupport::Cache::AtomicDalliStore#ttl_set has approx 6 statements
with { |c| c.set(key, "", expiry, raw: true) } - ActiveSupport::Cache::AtomicDalliStore#ttl_set has the variable name 'c'
rescue Dalli::DalliError => e -
- ActiveSupport::Cache::AtomicDalliStore#ttl_set has the variable name 'e'
logger.error("DalliError: #{e.message}") if logger
raise if raise_errors?
false
end
def ttl_delete(key) - ActiveSupport::Cache::AtomicDalliStore#ttl_delete has approx 6 statements
with { |c| c.delete(key) } - ActiveSupport::Cache::AtomicDalliStore#ttl_delete has the variable name 'c'
rescue Dalli::DalliError => e -
- ActiveSupport::Cache::AtomicDalliStore#ttl_delete has the variable name 'e'
logger.error("DalliError: #{e.message}") if logger
raise if raise_errors?
false
end
end
end
end