<commit_before>module IdentityCache
  module QueryAPI
    extend ActiveSupport::Concern

    included do |base|
      base.private_class_method :require_if_necessary
      base.instance_eval(ruby = <<-CODE, __FILE__, __LINE__)
        private :expire_cache, :was_new_record?, :fetch_denormalized_cached_association,
                :populate_denormalized_cached_association
      CODE
      base.after_commit :expire_cache
      base.after_touch  :expire_cache
    end

    module ClassMethods
      # Similar to ActiveRecord::Base#exists? will return true if the id can be
      # found in the cache.
      def exists_with_identity_cache?(id)
        !!fetch_by_id(id)
      end

      # Default fetcher added to the model on inclusion, it behaves like
      # ActiveRecord::Base.find_by_id
      def fetch_by_id(id)
        if IdentityCache.should_cache?

          require_if_necessary do
            object = IdentityCache.fetch(rails_cache_key(id)){ resolve_cache_miss(id) }<commit_msg>Make exists_with_identity_cache? rdoc explicit that it doesn't only lookup in the cache<commit_after>module IdentityCache
  module QueryAPI
    extend ActiveSupport::Concern

    included do |base|
      base.private_class_method :require_if_necessary
      base.instance_eval(ruby = <<-CODE, __FILE__, __LINE__)
        private :expire_cache, :was_new_record?, :fetch_denormalized_cached_association,
                :populate_denormalized_cached_association
      CODE
      base.after_commit :expire_cache
      base.after_touch  :expire_cache
    end

    module ClassMethods
      # Similar to ActiveRecord::Base#exists? will return true if the id can be
      # found in the cache or in the DB.
      def exists_with_identity_cache?(id)
        !!fetch_by_id(id)
      end

      # Default fetcher added to the model on inclusion, it behaves like
      # ActiveRecord::Base.find_by_id
      def fetch_by_id(id)
        if IdentityCache.should_cache?

          require_if_necessary do
            object = IdentityCache.fetch(rails_cache_key(id)){ resolve_cache_miss(id) }
{'fraction_non_alphanumeric': 0.06283228612856452, 'fraction_numerical': 0.0, 'mean_word_length': 3.1733870967741935, 'pattern_counts': {'":': 0, '<': 7, '<?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': '6791838', 'n_tokens_mistral': 612, 'n_tokens_neox': 592, 'n_words': 151}