# File lib/bundler/runtime.rb, line 111
    def cache(custom_path = nil)
      cache_path = Bundler.app_cache(custom_path)
      SharedHelpers.filesystem_access(cache_path) do |p|
        FileUtils.mkdir_p(p)
      end unless File.exist?(cache_path)

      Bundler.ui.info "Updating files in #{Bundler.settings.app_cache_path}"

      # Do not try to cache specification for the gem described by the .gemspec
      root_gem_name = nil
      if gemspec_cache_hash = Bundler.instance_variable_get(:@gemspec_cache)
        gemspec = gemspec_cache_hash.values.first
        root_gem_name = gemspec.name unless gemspec.nil?
      end
      specs.each do |spec|
        next if spec.name == "bundler"
        next if File.exist?("#{root_gem_name}.gemspec") && spec.source.class == Bundler::Source::Path && root_gem_name && spec.name == root_gem_name
        spec.source.send(:fetch_gem, spec) if Bundler.settings[:cache_all_platforms] && spec.source.respond_to?(:fetch_gem, true)
        spec.source.cache(spec, custom_path) if spec.source.respond_to?(:cache)
      end

      Dir[cache_path.join("*/.git")].each do |git_dir|
        FileUtils.rm_rf(git_dir)
        FileUtils.touch(File.expand_path("../.bundlecache", git_dir))
      end

      prune_cache(cache_path) unless Bundler.settings[:no_prune]
    end