<commit_before>module Cms
  module Caching
    module ClassMethods
      def cacheable opts = {}
        self.class_variable_set :@@cacheable, true
        opts[:expires_on] ||= nil


        self.after_create :expire
        self.after_update :expire
        self.after_destroy :expire


      end

      def cacheable_resource opts = {}
        opts[:pages] ||= [:home]
        opts[:pages] ||= []
      end

      def cacheable?
        if !self.class_variable_defined?(:@@cacheable)
          return false
        end
        self.class_variable_get :@@cacheable || false
      end

      def self.depends_on(*keys, **options)

      end
    end

    module InstanceMethods
      def cacheable?
        self.class.cacheable?
      end

      def cached?
        File.exists?(self.full_cache_path)
      end

      def clear_cache(include_dependencies = true)
        # _get_action_controller.expire_page(self.cache_path)
        # if include_dependencies && cache_dependencies.present?
        #   cache_dependencies.each do |dep|
        #     _get_action_controller.expire_page(dep.cache_path)
        #   end
        # end


        instances = cache_instances.try(:uniq)
        if instances.present?
          instances.each do |instance|
            if instance.is_a?(Array) || instance.is_a?(ActiveRecord::Relation)
              instance.all.each do |child|
                begin
                  paths = child.cache_path
                rescue
                  next
                end
                paths.each do |path|
                  _get_action_controller.expire_page(path) rescue nil
                end
              end
            else
              begin
                paths = instance.cache_path
              rescue
                next
              end
              paths.each do |path|
                _get_action_controller.expire_page(path) rescue nil
              end
            end
          end
        end<commit_msg>caching: fix error when not relation<commit_after>module Cms
  module Caching
    module ClassMethods
      def cacheable opts = {}
        self.class_variable_set :@@cacheable, true
        opts[:expires_on] ||= nil


        self.after_create :expire
        self.after_update :expire
        self.after_destroy :expire


      end

      def cacheable_resource opts = {}
        opts[:pages] ||= [:home]
        opts[:pages] ||= []
      end

      def cacheable?
        if !self.class_variable_defined?(:@@cacheable)
          return false
        end
        self.class_variable_get :@@cacheable || false
      end

      def self.depends_on(*keys, **options)

      end
    end

    module InstanceMethods
      def cacheable?
        self.class.cacheable?
      end

      def cached?
        File.exists?(self.full_cache_path)
      end

      def clear_cache(include_dependencies = true)
        # _get_action_controller.expire_page(self.cache_path)
        # if include_dependencies && cache_dependencies.present?
        #   cache_dependencies.each do |dep|
        #     _get_action_controller.expire_page(dep.cache_path)
        #   end
        # end


        instances = cache_instances.try(:uniq)
        if instances.present?
          instances.each do |instance|
            if instance.is_a?(Array) || instance.is_a?(ActiveRecord::Relation)
              items = instance.all if instance.is_a?(ActiveRecord::Relation)
              items.each do |child|
                begin
                  paths = child.cache_path
                rescue
                  next
                end
                paths.each do |path|
                  _get_action_controller.expire_page(path) rescue nil
                end
              end
            else
              begin
                paths = instance.cache_path
              rescue
                next
              end
              paths.each do |path|
                _get_action_controller.expire_page(path) rescue nil
              end
            end
          end
        end
{'fraction_non_alphanumeric': 0.0722291407222914, 'fraction_numerical': 0.0, 'mean_word_length': 1.5068664169787764, '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': '3697087', 'n_tokens_mistral': 1104, 'n_tokens_neox': 1064, 'n_words': 230}