Module: Switchman::ActiveSupport::Cache::ClassMethods

Defined in:
lib/switchman/active_support/cache.rb

Instance Method Summary collapse

Instance Method Details

#lookup_store(*store_options) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/switchman/active_support/cache.rb', line 23

def lookup_store(*store_options)
  store = super
  # must use the string name, otherwise it will try to auto-load the constant
  # and we don't want to require redis in this file (since it's not a hard dependency)
  # rubocop:disable Style/ClassEqualityComparison
  if store.class.name == "ActiveSupport::Cache::RedisCacheStore" &&
     !(::ActiveSupport::Cache::RedisCacheStore <= RedisCacheStore)
    ::ActiveSupport::Cache::RedisCacheStore.prepend(RedisCacheStore)
  end
  # rubocop:enable Style/ClassEqualityComparison
  store.options[:namespace] ||= -> { Shard.current.default? ? nil : "shard_#{Shard.current.id}" }
  store
end

#lookup_stores(cache_store_config) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/switchman/active_support/cache.rb', line 7

def lookup_stores(cache_store_config)
  result = {}
  cache_store_config.each do |key, value|
    next if value.is_a?(String)

    result[key] = ::ActiveSupport::Cache.lookup_store(value)
  end

  cache_store_config.each do |key, value| # rubocop:disable Style/CombinableLoops
    next unless value.is_a?(String)

    result[key] = result[value]
  end
  result
end