Sha256: e0394568f4a6249c7cd8684ac09a731832a5d381809c4823dd29c1f0d1bf83ad

Contents?: true

Size: 1.83 KB

Versions: 12

Compression:

Stored size: 1.83 KB

Contents

# typed: 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

12 entries across 12 versions & 1 rubygems

Version Path
ddtrace-1.9.0 lib/datadog/tracing/contrib/active_support/cache/redis.rb
ddtrace-1.8.0 lib/datadog/tracing/contrib/active_support/cache/redis.rb
ddtrace-1.7.0 lib/datadog/tracing/contrib/active_support/cache/redis.rb
ddtrace-1.6.1 lib/datadog/tracing/contrib/active_support/cache/redis.rb
ddtrace-1.6.0 lib/datadog/tracing/contrib/active_support/cache/redis.rb
ddtrace-1.5.2 lib/datadog/tracing/contrib/active_support/cache/redis.rb
ddtrace-1.5.1 lib/datadog/tracing/contrib/active_support/cache/redis.rb
ddtrace-1.5.0 lib/datadog/tracing/contrib/active_support/cache/redis.rb
ddtrace-1.4.2 lib/datadog/tracing/contrib/active_support/cache/redis.rb
ddtrace-1.4.1 lib/datadog/tracing/contrib/active_support/cache/redis.rb
ddtrace-1.4.0 lib/datadog/tracing/contrib/active_support/cache/redis.rb
ddtrace-1.3.0 lib/datadog/tracing/contrib/active_support/cache/redis.rb