Sha256: b488ebf7b2f6157645fc76f87f0810738982bf013b6ae53a1403c314b908a06c

Contents?: true

Size: 1.23 KB

Versions: 22

Compression:

Stored size: 1.23 KB

Contents

# frozen_string_literal: true

module Switchman
  module ActiveSupport
    module Cache
      module ClassMethods
        def lookup_store(*store_options)
          store = super
          # can't use defined?, because it's a _ruby_ autoloaded constant,
          # so just checking that will cause it to get required
          if store.class.name == "ActiveSupport::Cache::RedisCacheStore" && !::ActiveSupport::Cache::RedisCacheStore.ancestors.include?(RedisCacheStore)
            ::ActiveSupport::Cache::RedisCacheStore.prepend(RedisCacheStore)
          end
          store.options[:namespace] ||= lambda { Shard.current.default? ? nil : "shard_#{Shard.current.id}" }
          store
        end
      end

      module RedisCacheStore
        def clear(namespace: nil, **)
          # RedisCacheStore tries to be smart and only clear the cache under your namespace, if you have one set
          # unfortunately, it uses the keys command, which is extraordinarily inefficient in a large redis instance
          # fortunately, we can assume we control the entire instance, because we set up the namespacing, so just
          # always unset it temporarily for clear calls
          namespace = nil
          super
        end
      end
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
switchman-2.2.3 lib/switchman/active_support/cache.rb
switchman-2.2.2 lib/switchman/active_support/cache.rb
switchman-2.2.1 lib/switchman/active_support/cache.rb
switchman-2.2.0 lib/switchman/active_support/cache.rb
switchman-2.1.6 lib/switchman/active_support/cache.rb
switchman-2.1.5 lib/switchman/active_support/cache.rb
switchman-2.1.4 lib/switchman/active_support/cache.rb
switchman-2.1.3 lib/switchman/active_support/cache.rb
switchman-2.1.2 lib/switchman/active_support/cache.rb
switchman-2.1.1 lib/switchman/active_support/cache.rb
switchman-2.1.0 lib/switchman/active_support/cache.rb
switchman-2.0.13 lib/switchman/active_support/cache.rb
switchman-2.0.12 lib/switchman/active_support/cache.rb
switchman-2.0.11 lib/switchman/active_support/cache.rb
switchman-2.0.10 lib/switchman/active_support/cache.rb
switchman-2.0.9 lib/switchman/active_support/cache.rb
switchman-2.0.8 lib/switchman/active_support/cache.rb
switchman-2.0.7 lib/switchman/active_support/cache.rb
switchman-2.0.6 lib/switchman/active_support/cache.rb
switchman-2.0.5 lib/switchman/active_support/cache.rb