<commit_before>require 'digest/md5'
require 'msgpack'

module Bootscale
  class FileStorage
    def initialize(directory)
      @directory = directory
    end

    def load(load_path)
      path = cache_path(load_path)
      MessagePack.load(File.read(path)) if File.exist?(path)
    end

    def dump(load_path, cache)
      File.open(cache_path(load_path), 'wb+') { |f| f.write(MessagePack.dump(cache)) }
    end

    def cache_path(load_path)
      hash = Digest::MD5.hexdigest((load_path + [RUBY_VERSION, Bootscale::VERSION, MessagePack::VERSION]).join('|'))
      File.join(@directory, "bootscale-#{hash}.msgpack")
    end
  end
end<commit_msg>Do not override existing file cache<commit_after>require 'digest/md5'
require 'msgpack'

module Bootscale
  class FileStorage
    def initialize(directory)
      @directory = directory
    end

    def load(load_path)
      path = cache_path(load_path)
      MessagePack.load(File.read(path)) if File.exist?(path)
    end

    def dump(load_path, cache)
      path = cache_path(load_path)
      return if File.exist?(path)
      File.open(path, 'wb+') { |f| f.write(MessagePack.dump(cache)) }
    end

    def cache_path(load_path)
      hash = Digest::MD5.hexdigest((load_path + [RUBY_VERSION, Bootscale::VERSION, MessagePack::VERSION]).join('|'))
      File.join(@directory, "bootscale-#{hash}.msgpack")
    end
  end
end
{'fraction_non_alphanumeric': 0.12900874635568513, 'fraction_numerical': 0.0029154518950437317, 'mean_word_length': 3.6860068259385668, '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': '7633270', 'n_tokens_mistral': 460, 'n_tokens_neox': 452, 'n_words': 91}