I’m confused about the code block in the Bundler (Ruby)
section here:
https://circleci.com/docs/2.0/caching/#bundler-ruby
The code block in question is:
- run: bundle install & bundle clean
- restore_cache:
keys:
# when lock file changes, use increasingly general patterns to restore cache
- v1-gem-cache-{{ arch }}-{{ .Branch }}-{{ checksum "Gemfile.lock" }}
- v1-gem-cache-{{ arch }}-{{ .Branch }}-
- v1-gem-cache-{{ arch }}-
- save_cache:
paths:
- ~/.bundle
key: v1-gem-cache-{{ arch }}-{{ .Branch }}-{{ checksum "Gemfile.lock" }}
I’m reading this process as:
- Run
bundle install
before the cache is put in place (a full gem installation time before restoring cache, which negates the time-saving benefits of a cache) and then runbundle clean
- Restore the cache over the installed gems
- Don’t do anything (between
restore_cache
andsave_cache
steps) - Save the new cache
Am I understanding that process correctly?
This looks to me like restore_cache
and save_cache
steps are not going to be effective, because the full bundle install
time would have already been spent.
If I’m understanding things, would this be a more efficient process?
- restore_cache:
keys:
# when lock file changes, use increasingly general patterns to restore cache
- v1-gem-cache-{{ arch }}-{{ .Branch }}-{{ checksum "Gemfile.lock" }}
- v1-gem-cache-{{ arch }}-{{ .Branch }}-
- v1-gem-cache-{{ arch }}-
- run: bundle install & bundle clean
- save_cache:
paths:
- ~/.bundle
key: v1-gem-cache-{{ arch }}-{{ .Branch }}-{{ checksum "Gemfile.lock" }}
If I’m not understanding this correctly, can anyone help clarify how the suggested code block works?