Sha256: 6a4642126419f20a545dbb4e3e274fa40dc2988ae8d675e13040612bd6ded6f4

Contents?: true

Size: 1.85 KB

Versions: 26

Compression:

Stored size: 1.85 KB

Contents

# frozen_string_literal: true

require_relative 'patcher'

module Datadog
  module Tracing
    module Contrib
      module ActiveSupport
        module Cache
          # Support for Redis with ActiveSupport
          module Redis
            # Patching behavior for Redis with ActiveSupport
            module Patcher
              # For Rails < 5.2 w/ redis-activesupport...
              # When Redis is used, we can't only patch Cache::Store as it is
              # Cache::RedisStore, a sub-class of it that is used, in practice.
              # We need to do a per-method monkey patching as some of them might
              # be redefined, and some of them not. The latest version of redis-activesupport
              # redefines write but leaves untouched read and delete:
              # https://github.com/redis-store/redis-activesupport/blob/v4.1.5/lib/active_support/cache/redis_store.rb
              #
              # For Rails >= 5.2 w/o redis-activesupport...
              # ActiveSupport includes a Redis cache store internally, and does not require these overrides.
              # https://github.com/rails/rails/blob/master/activesupport/lib/active_support/cache/redis_cache_store.rb
              def patch_redis?(meth)
                !Gem.loaded_specs['redis-activesupport'].nil? \
                  && defined?(::ActiveSupport::Cache::RedisStore) \
                  && ::ActiveSupport::Cache::RedisStore.instance_methods(false).include?(meth)
              end

              def cache_store_class(meth)
                if patch_redis?(meth)
                  ::ActiveSupport::Cache::RedisStore
                else
                  super
                end
              end
            end

            # Decorate Cache patcher with Redis support
            Cache::Patcher.singleton_class.prepend(Redis::Patcher)
          end
        end
      end
    end
  end
end

Version data entries

26 entries across 26 versions & 2 rubygems

Version Path
ddtrace-1.23.3 lib/datadog/tracing/contrib/active_support/cache/redis.rb
ddtrace-1.23.2 lib/datadog/tracing/contrib/active_support/cache/redis.rb
datadog-2.1.0 lib/datadog/tracing/contrib/active_support/cache/redis.rb
datadog-2.0.0 lib/datadog/tracing/contrib/active_support/cache/redis.rb
ddtrace-1.23.1 lib/datadog/tracing/contrib/active_support/cache/redis.rb
datadog-2.0.0.beta2 lib/datadog/tracing/contrib/active_support/cache/redis.rb
ddtrace-1.22.0 lib/datadog/tracing/contrib/active_support/cache/redis.rb
datadog-2.0.0.beta1 lib/datadog/tracing/contrib/active_support/cache/redis.rb
ddtrace-1.21.1 lib/datadog/tracing/contrib/active_support/cache/redis.rb
ddtrace-1.21.0 lib/datadog/tracing/contrib/active_support/cache/redis.rb
ddtrace-1.20.0 lib/datadog/tracing/contrib/active_support/cache/redis.rb
ddtrace-1.19.0 lib/datadog/tracing/contrib/active_support/cache/redis.rb
ddtrace-1.18.0 lib/datadog/tracing/contrib/active_support/cache/redis.rb
ddtrace-1.17.0 lib/datadog/tracing/contrib/active_support/cache/redis.rb
ddtrace-1.16.2 lib/datadog/tracing/contrib/active_support/cache/redis.rb
ddtrace-1.16.1 lib/datadog/tracing/contrib/active_support/cache/redis.rb
ddtrace-1.16.0 lib/datadog/tracing/contrib/active_support/cache/redis.rb
ddtrace-1.15.0 lib/datadog/tracing/contrib/active_support/cache/redis.rb
ddtrace-1.14.0 lib/datadog/tracing/contrib/active_support/cache/redis.rb
ddtrace-1.13.1 lib/datadog/tracing/contrib/active_support/cache/redis.rb