Skip to content

GitLab CI Cache Restore Error Fix

DodaTech Updated 2026-06-24 2 min read

In this tutorial, you'll learn about GitLab CI Cache Restore Error Fix. We cover key concepts, practical examples, and best practices.

Your GitLab CI job reports No cache found or Restoring cache — skipped — the cache key doesn't match any existing cache, or the cache scope prevents sharing between branches.

The Problem

# WRONG — cache key that changes every time
build:
  script:
    - npm ci
  cache:
    key: npm-cache-$CI_COMMIT_SHA
    paths:
      - node_modules/
Checking cache for npm-cache-abc123... no cache found

$CI_COMMIT_SHA changes on every commit. The cache key is unique every time, which defeats the purpose of caching. No cache is ever reused.

Step-by-Step Fix

1. Use a stable cache key with fallback

build:
  script:
    - npm ci
  cache:
    key:
      files:
        - package-lock.json
    paths:
      - node_modules/

GitLab automatically computes a hash of package-lock.json. The cache is valid until the lock file changes.

2. Use prefix-based cache key with multiple files

cache:
  key:
    files:
      - package-lock.json
      - .nvmrc
    prefix: $CI_JOB_NAME
  paths:
    - node_modules/

3. Set cache scope for branch sharing

cache:
  key: $CI_COMMIT_REF_SLUG
  paths:
    - vendor/bundle

$CI_COMMIT_REF_SLUG includes the branch name. Caches are shared across pipelines on the same branch but not across branches. Use a fixed prefix to share across branches.

4. Use separate caches for different jobs

npm-cache:
  variables:
    npm_config_cache: "$CI_PROJECT_DIR/.npm"
  cache:
    key:
      files:
        - package-lock.json
    paths:
      - .npm

bundle-cache:
  cache:
    key:
      files:
        - Gemfile.lock
    paths:
      - vendor/bundle

Expected output:

Checking cache for package-lock.json hash... cache hit
Restoring cache from job "build"...
✓ node_modules restored from cache

Prevention Tips

  • Use key:files: with lock files for stable cache keys
  • Use prefix: to group caches by job name
  • Set key: $CI_COMMIT_REF_SLUG for branch-specific caching
  • Use separate cache entries for different dependency types
  • Clear caches manually from Settings > CI/CD when needed

Common Mistakes with ci cache error

  1. Forgetting that lazy evaluation defers computation until the value is forced, causing space leaks with unevaluated thunks
  2. Using return to exit a function early instead of wrapping a pure value in the monad
  3. Mixing let bindings with <- bindings in do notation, producing type errors

These mistakes appear frequently in real-world GITLAB code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.

Practice Exercise

Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.

This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.

FAQ

### Why is my cache not restoring across pipelines on the same branch?

Check the cache key. If it includes $CI_PIPELINE_ID or $CI_JOB_ID, it changes every pipeline. Use files: with a lock file or $CI_COMMIT_REF_SLUG. Also check if the cache was expired — GitLab caches have a TTL (default 7 days for most plans).

What's the difference between cache and artifacts in GitLab CI?

Cache stores dependency directories (node_modules, vendor/bundle) across pipelines to speed up builds. Artifacts store build outputs (JARs, Docker images, reports) between stages within a pipeline. Use cache for dependencies, artifacts for build results.

How do I clear a corrupted cache in GitLab CI?

Go to CI/CD > Pipeline Cache in the project settings and click "Clear caches". You can also change the cache key (add a version prefix like v2-) to force new cache entries. The old cache expires naturally.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro