Module: Datadog::Contrib::ActiveSupport::Cache::Redis::Patcher
- Defined in:
- lib/ddtrace/contrib/active_support/cache/redis.rb
Overview
Patching behavior for Redis with ActiveSupport
Instance Method Summary collapse
- #cache_store_class(meth) ⇒ Object
-
#patch_redis?(meth) ⇒ Boolean
For Rails < 5.2 w/ redis-activesupport…
Instance Method Details
#cache_store_class(meth) ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/ddtrace/contrib/active_support/cache/redis.rb', line 28 def cache_store_class(meth) if patch_redis?(meth) ::ActiveSupport::Cache::RedisStore else super end end |
#patch_redis?(meth) ⇒ Boolean
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: github.com/redis-store/redis-activesupport/blob/master/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. github.com/rails/rails/blob/master/activesupport/lib/active_support/cache/redis_cache_store.rb
22 23 24 25 26 |
# File 'lib/ddtrace/contrib/active_support/cache/redis.rb', line 22 def patch_redis?(meth) !Gem.loaded_specs['redis-activesupport'].nil? \ && defined?(::ActiveSupport::Cache::RedisStore) \ && ::ActiveSupport::Cache::RedisStore.instance_methods(false).include?(meth) end |