<commit_before>if CANVAS_RAILS3
  # In rails4, this is always true, and in rails5, this setter is removed
  ActiveSupport::Cache::Store.instrument = true
end

%w[read write delete exist? generate].each do |method|
  ActiveSupport::Notifications.subscribe("cache_#{method}.active_support") do |_name, start, finish, _id, options|
    key = options[:key]
    elapsed_time = finish - start
    Rails.logger.debug("CacheStore: #{method} #{key.inspect} #{"%.4f" % elapsed_time}")
  end
end
<commit_msg>fix cache store instrumentation (logging) under Passenger<commit_after># In rails4, this is always true, and in rails5, this setter is removed.
# In other words, just remove this whole block of code when we drop rails3 support.
if CANVAS_RAILS3
  ActiveSupport::Cache::Store.instrument = true
  if defined?(PhusionPassenger)
    # For whatever reason this is a thread-local setting, so under Passenger we
    # need to set it on each handler thread. Note that even in process mode,
    # Passenger spins up a separate thread in each process for the actual rack
    # handler.
    PhusionPassenger.on_event(:starting_request_handler_thread) do
      ActiveSupport::Cache::Store.instrument = true
    end
  end
end

%w[read write delete exist? generate].each do |method|
  ActiveSupport::Notifications.subscribe("cache_#{method}.active_support") do |_name, start, finish, _id, options|
    key = options[:key]
    elapsed_time = finish - start
    Rails.logger.debug("CacheStore: #{method} #{key.inspect} #{"%.4f" % elapsed_time}")
  end
end

{'fraction_non_alphanumeric': 0.10279765777488614, 'fraction_numerical': 0.005855562784645413, 'mean_word_length': 4.592727272727273, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4377442', 'n_tokens_mistral': 469, 'n_tokens_neox': 463, 'n_words': 158}