Caches¶
Goal
Learn how to...
- define caches
- store data in a cache
- restore data from a cache
- avoid relying on the cache
Task 1: Test caching¶
The cache is used by adding the keyword cache
in a pipeline job, a job template or in the default
section. Let's give it a try:
- Add a job
test_cache
to the first stage - Download dependency information from the uniget project:
- Use the official example for Go to enable caching
- Instead of
go test
rungo mod download
to download dependencies only
Afterwards check the pipeline in the GitLab UI. You should see a successful pipeline run. Retry the job to see the effect of the cache.
Hint (Click if you are stuck)
Use the .go-cache
job template from the official example for Go.
Solution (Click if you are stuck)
.gitlab-ci-yml
:
This was just a demonstration. The changes will not be preserved in the following chapters.
Task 2: Add caching¶
Now, integrate the job template .go-cache
into the pipeline and use it for the jobs build
and unit_test
.
Afterwards check the pipeline in the GitLab UI. You should see a successful pipeline run.
Solution (Click if you are stuck)
go.yaml
:
If you want to jump to the solution, execute the following command: