Maven / GitLab CI Basics Interview Questions
What is pipeline caching and how do you configure cache keys?
Cache in GitLab CI speeds up jobs by storing files (typically dependencies like node_modules/) between pipeline runs. The cache key determines which jobs share a cache and when the cache is invalidated.
# Basic cache with branch-scoped key: cache: key: "$CI_COMMIT_REF_SLUG" # different cache per branch paths: - .npm/ - node_modules/ # Cache keyed to dependency file (invalidates when file changes): cache: key: files: - package-lock.json # cache key changes when lockfile changes prefix: "$CI_COMMIT_REF_SLUG" paths: - node_modules/ # Cache policies (pull-push is default): job-with-readonly-cache: cache: key: $CI_COMMIT_REF_SLUG paths: - node_modules/ policy: pull # only download cache, never update it job-that-updates-cache: cache: policy: push # only upload, skip downloading # Per-job cache: build: cache: key: "build-$CI_COMMIT_REF_SLUG" paths: [dist/] test: cache: key: "deps-$CI_COMMIT_REF_SLUG" paths: [node_modules/]
| Policy | Behaviour |
|---|---|
| pull-push (default) | Download cache at start, upload updated cache at end |
| pull | Download cache only - never update (read-only) |
| push | Upload cache only - never download (write-only) |
Use policy: pull for most jobs that just use the cache, and one dedicated job with policy: push or pull-push to update it. This prevents multiple parallel jobs from overwriting each other's cache updates.
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
