Add global gem cache shared by RubyGems and Bundler #9230
+142
−4
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What was the end-user or developer problem that led to this PR?
Attempts to implement #7249. I read about this issue in this recent blog post by @tenderlove.
I will admit that I am both new to this repo and that the code was primarily generated with Claude Code. However, I reviewed it (have a lot of Ruby experience) and it seems reasonable. Additionally, I had it write some automated tests and a script to test it out end-to-end. I am hoping this changeset could at least serve as a conversation starter to make sure the requirements are clear, and since it did not take long to implement, I have low attachment to it, so open to feedback.
What is your fix for the problem, implemented in this PR?
Add opt-in support for a global .gem file cache at ~/.cache/gem/gems (respects XDG_CACHE_HOME). This allows sharing cached gems across all Ruby installations and between RubyGems and Bundler.
Enable via:
When enabled, RubyGems checks the global cache before downloading and copies downloaded gems to the cache. Bundler's existing global_gem_cache setting now uses the same unified cache location.
Note: #7249 indicates that it's a placeholder for opting everyone in to this behavior for Bundler and Rubygems, but I thought that this might be better for the next version bump since it might have some unexpected behaviors for folks. I think it would be a small code change to make it opt-out, but might be more of a development challenge to do so IMO.
Make sure the following tasks are checked