Updated

app/lib/active_support/cache / atomic_dalli_store.rb

D
88 lines of codes
10 methods
8.1 complexity/method
2 churn
81.06 complexity
54 duplications
require 'active_support/cache/dalli_store' module ActiveSupport module Cache class AtomicDalliStore < DalliStore
  1. ActiveSupport::Cache::AtomicDalliStore has no descriptive comment
def fetch(name, options = nil)
  1. ActiveSupport::Cache::AtomicDalliStore takes parameters ['name', 'options'] to 6 methods Locations: 0 1 2 3 4 5
  2. ActiveSupport::Cache::AtomicDalliStore#fetch has approx 7 statements
if block_given? result = read(name, options)
  1. ActiveSupport::Cache::AtomicDalliStore#fetch calls 'read(name, options)' 2 times Locations: 0 1
if result.nil?
  1. 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)
  1. ActiveSupport::Cache::AtomicDalliStore#fetch calls 'read(name, options)' 2 times Locations: 0 1
end end def read(name, options = nil)
  1. ActiveSupport::Cache::AtomicDalliStore takes parameters ['name', 'options'] to 6 methods Locations: 0 1 2 3 4 5
super.tap do |result| if result.present? return nil if lock!(name, options) end end end def write(name, value, options = nil)
  1. ActiveSupport::Cache::AtomicDalliStore takes parameters ['name', 'options'] to 6 methods Locations: 0 1 2 3 4 5
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)
  1. ActiveSupport::Cache::AtomicDalliStore takes parameters ['name', 'options'] to 6 methods Locations: 0 1 2 3 4 5
ttl_delete(ttl_key(name, options)) && super end private def lock!(name, options)
  1. ActiveSupport::Cache::AtomicDalliStore takes parameters ['name', 'options'] to 6 methods Locations: 0 1 2 3 4 5
  2. 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)
  1. ActiveSupport::Cache::AtomicDalliStore takes parameters ['name', 'options'] to 6 methods Locations: 0 1 2 3 4 5
"#{namespaced_key(name, options)}.ttl" end def ttl_get(key)
  1. ActiveSupport::Cache::AtomicDalliStore#ttl_get has approx 6 statements
with { |c| c.get(key, raw: true) }
  1. ActiveSupport::Cache::AtomicDalliStore#ttl_get has the variable name 'c'
rescue Dalli::DalliError => e
  1. ActiveSupport::Cache::AtomicDalliStore#ttl_get has the variable name 'e'
logger.error("DalliError: #{e.message}") if logger
  1. ActiveSupport::Cache::AtomicDalliStore tests 'logger' at least 4 times Locations: 0 1 2 3
raise if raise_errors?
  1. ActiveSupport::Cache::AtomicDalliStore tests 'raise_errors?' at least 4 times Locations: 0 1 2 3
nil end def ttl_add(key)
  1. ActiveSupport::Cache::AtomicDalliStore#ttl_add has approx 6 statements
with { |c| c.add(key, "", 10, raw: true) }
  1. ActiveSupport::Cache::AtomicDalliStore#ttl_add has the variable name 'c'
rescue Dalli::DalliError => e
  1. Identical code found in 3 nodes Locations: 0 1 2
  2. ActiveSupport::Cache::AtomicDalliStore#ttl_add has the variable name 'e'
logger.error("DalliError: #{e.message}") if logger
  1. ActiveSupport::Cache::AtomicDalliStore tests 'logger' at least 4 times Locations: 0 1 2 3
raise if raise_errors?
  1. ActiveSupport::Cache::AtomicDalliStore tests 'raise_errors?' at least 4 times Locations: 0 1 2 3
false end def ttl_set(key, expiry)
  1. ActiveSupport::Cache::AtomicDalliStore#ttl_set has approx 6 statements
with { |c| c.set(key, "", expiry, raw: true) }
  1. ActiveSupport::Cache::AtomicDalliStore#ttl_set has the variable name 'c'
rescue Dalli::DalliError => e
  1. Identical code found in 3 nodes Locations: 0 1 2
  2. ActiveSupport::Cache::AtomicDalliStore#ttl_set has the variable name 'e'
logger.error("DalliError: #{e.message}") if logger
  1. ActiveSupport::Cache::AtomicDalliStore tests 'logger' at least 4 times Locations: 0 1 2 3
raise if raise_errors?
  1. ActiveSupport::Cache::AtomicDalliStore tests 'raise_errors?' at least 4 times Locations: 0 1 2 3
false end def ttl_delete(key)
  1. ActiveSupport::Cache::AtomicDalliStore#ttl_delete has approx 6 statements
with { |c| c.delete(key) }
  1. ActiveSupport::Cache::AtomicDalliStore#ttl_delete has the variable name 'c'
rescue Dalli::DalliError => e
  1. Identical code found in 3 nodes Locations: 0 1 2
  2. ActiveSupport::Cache::AtomicDalliStore#ttl_delete has the variable name 'e'
logger.error("DalliError: #{e.message}") if logger
  1. ActiveSupport::Cache::AtomicDalliStore tests 'logger' at least 4 times Locations: 0 1 2 3
raise if raise_errors?
  1. ActiveSupport::Cache::AtomicDalliStore tests 'raise_errors?' at least 4 times Locations: 0 1 2 3
false end end end end