Module: Datadog::Tracing::Contrib::ActiveSupport::Cache::Instrumentation::PreserveOriginalKey

Defined in:
lib/datadog/tracing/contrib/active_support/cache/instrumentation.rb

Overview

Save the original, user-supplied cache key, before it gets normalized.

Normalized keys can include internal implementation detail, for example FileStore keys include temp directory names, which changes on every run, making it impossible to group by the cache key afterward. Also, the user is never exposed to the normalized key, and only sets/gets using the original key.

Instance Method Summary collapse

Instance Method Details

#merged_options(call_options) ⇒ Object

Ensure we don’t pollute the default Store instance ‘options` in #normalize_key. In most cases, `merged_options` returns a new hash, but we check for cases where it reuses the instance hash.



210
211
212
213
214
215
216
217
218
# File 'lib/datadog/tracing/contrib/active_support/cache/instrumentation.rb', line 210

def merged_options(call_options)
  ret = super

  if ret.equal?(options)
    ret.dup
  else
    ret
  end
end

#normalize_key(key, options) ⇒ Object

Stores the original keys in the options hash, as an array of keys. It’s important to keep all the keys for multi-key operations. For single-key operations, the key is stored as an array of a single element.



199
200
201
202
203
204
205
# File 'lib/datadog/tracing/contrib/active_support/cache/instrumentation.rb', line 199

def normalize_key(key, options)
  orig_keys = options[:dd_original_keys] || []
  orig_keys << key
  options[:dd_original_keys] = orig_keys

  super
end