<commit_before>class Prop
  class RateLimitExceededError < RuntimeError
  end

  class << self
    attr_accessor :store
    attr_accessor :handles

    def configure(handle, options)
      raise RuntimeError.new("Invalid threshold setting") unless options[:threshold].to_i > 0
      raise RuntimeError.new("Invalid interval setting") unless options[:interval].to_i > 0

      self.handles ||= {}
      self.handles[handle] = options
    end

    def throttle!(options)
      cache_key = "#{options[:key]}/#{Time.now.to_i / options[:interval]}"
      counter   = store[cache_key].to_i

      if counter >= options[:threshold]
        raise Prop::RateLimitExceededError.new("#{options[:key]} threshold #{options[:threshold]} exceeded")
      else
        store[cache_key] = counter + 1
      end
    end

    def method_missing(handle, *arguments, &block)
      self.handles ||= {}
      if options = handles[handle]
        throttle!(options.merge(:key => "#{handle}/#{arguments.first}"))
      else
        super
      end
    end
  end
end<commit_msg>Prefix cache key<commit_after>class Prop
  class RateLimitExceededError < RuntimeError
  end

  class << self
    attr_accessor :store
    attr_accessor :handles

    def configure(handle, options)
      raise RuntimeError.new("Invalid threshold setting") unless options[:threshold].to_i > 0
      raise RuntimeError.new("Invalid interval setting") unless options[:interval].to_i > 0

      self.handles ||= {}
      self.handles[handle] = options
    end

    def throttle!(options)
      cache_key = "prop/#{options[:key]}/#{Time.now.to_i / options[:interval]}"
      counter   = store[cache_key].to_i

      if counter >= options[:threshold]
        raise Prop::RateLimitExceededError.new("#{options[:key]} threshold #{options[:threshold]} exceeded")
      else
        store[cache_key] = counter + 1
      end
    end

    def method_missing(handle, *arguments, &block)
      self.handles ||= {}
      if options = handles[handle]
        throttle!(options.merge(:key => "#{handle}/#{arguments.first}"))
      else
        super
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.12263257575757576, 'fraction_numerical': 0.002840909090909091, 'mean_word_length': 3.032442748091603, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, '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': '166892', 'n_tokens_mistral': 629, 'n_tokens_neox': 604, 'n_words': 141}