<commit_before>module Gitlab
  module Metrics
    module Subscribers
      # Class for tracking the total time spent in Rails cache calls
      class RailsCache < ActiveSupport::Subscriber
        attach_to :active_support

        def cache_read(event)
          increment(:cache_read, event.duration)
        end

        def cache_write(event)
          increment(:cache_write, event.duration)
        end

        def cache_delete(event)
          increment(:cache_delete, event.duration)
        end

        def cache_exist?(event)
          increment(:cache_exists, event.duration)
        end

        def increment(key, duration)
          return unless current_transaction

          current_transaction.increment(:cache_duration, duration)
          current_transaction.increment(:cache_count, 1)
          current_transaction.increment("#{key}_duration".to_sym, duration)
          current_transaction.increment("#{key}_count".to_sym, 1)
        end
<commit_msg>Instrument cache fetch hit and cache fetch misses<commit_after>module Gitlab
  module Metrics
    module Subscribers
      # Class for tracking the total time spent in Rails cache calls
      class RailsCache < ActiveSupport::Subscriber
        attach_to :active_support

        def cache_read(event)
          increment(:cache_read, event.duration)
        end

        def cache_write(event)
          increment(:cache_write, event.duration)
        end

        def cache_delete(event)
          increment(:cache_delete, event.duration)
        end

        def cache_exist?(event)
          increment(:cache_exists, event.duration)
        end

        def cache_fetch_hit(event)
          return unless current_transaction

          current_transaction.increment(:cache_fetch_hit, 1)
        end

        def cache_generate(event)
          return unless current_transaction

          current_transaction.increment(:cache_fetch_miss, 1)
        end

        def increment(key, duration)
          return unless current_transaction

          current_transaction.increment(:cache_duration, duration)
          current_transaction.increment(:cache_count, 1)
          current_transaction.increment("#{key}_duration".to_sym, duration)
          current_transaction.increment("#{key}_count".to_sym, 1)
        end

{'fraction_non_alphanumeric': 0.06719022687609075, 'fraction_numerical': 0.002617801047120419, 'mean_word_length': 2.56055900621118, 'pattern_counts': {'":': 0, '<': 5, '<?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': '7580310', 'n_tokens_mistral': 594, 'n_tokens_neox': 576, 'n_words': 137}