<commit_before># frozen_string_literal: true

module Folio
  module ClearsPageCache
    extend ActiveSupport::Concern

    included do
      after_commit :clear_page_cache!
    end

    def clear_page_cache!
      return unless self.class.clears_page_cache_on_save?
      return unless Rails.application.config.action_controller.perform_caching
      cache_dir = Rails.application.config.action_controller.page_cache_directory
      return if cache_dir.blank?
      Dir.mktmpdir { |tmp_dir| FileUtils.mv cache_dir, tmp_dir }
    end

    module ClassMethods
      # overridable
      def clears_page_cache_on_save?
        true
      end
    end
  end
end
<commit_msg>check cache_dir existance before removal<commit_after># frozen_string_literal: true

module Folio
  module ClearsPageCache
    extend ActiveSupport::Concern

    included do
      after_commit :clear_page_cache!
    end

    def clear_page_cache!
      return unless self.class.clears_page_cache_on_save?
      return unless Rails.application.config.action_controller.perform_caching
      cache_dir = Rails.application.config.action_controller.page_cache_directory
      return if cache_dir.blank? || !File.exist?(cache_dir)
      Dir.mktmpdir { |tmp_dir| FileUtils.mv cache_dir, tmp_dir }
    end

    module ClassMethods
      # overridable
      def clears_page_cache_on_save?
        true
      end
    end
  end
end

{'fraction_non_alphanumeric': 0.05251798561151079, 'fraction_numerical': 0.0, 'mean_word_length': 3.29320987654321, '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': '2003660', 'n_tokens_mistral': 432, 'n_tokens_neox': 420, 'n_words': 91}