liveBook · Manning

Cache key

As explained in GitHub Actions in Action: Continuous integration and delivery for DevOps

A cache key is an identifier that determines which stored cache entry a request retrieves or replaces.

A cache key identifies the stored cache entry that a GitHub Actions request retrieves or replaces. Make it specific enough to avoid reusing stale dependencies or artifacts, commonly by combining the runner operating system with a lockfile hash. When the hash changes, the cache no longer matches. section 12.3.2 section 8.4.2

NuGet dependency cache

Configure the cache path, construct a key from the runner operating system and packages.lock.json contents, and provide an operating-system-specific restore prefix: - uses: actions/cache@v3 with: path: ~/.nuget/packages key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }} restore-keys: | ${{ runner.os }}-nuget- The hashFiles function computes SHA-256 values for matching files and combines them into one hash. Identical lockfile contents select the existing cache; changed contents produce a different key. section 12.3.2

Apply cache keys with these operational considerations:

  • Share a key between jobs when later jobs can reuse cached artifacts produced during continuous integration. section 8.4.2
  • Track storage usage and retention costs, especially for container-image caches, which can require considerable storage. section 12.3.2

How GitHub Actions in Action: Continuous integration and delivery for DevOps covers it

How deep it goes
Explains key composition, lockfile-based invalidation, restore prefixes, and SHA-256 hashing without detailing cache-service internals.
Examples
Uses npm, NuGet, and Docker cache configurations, including keys derived from runner.os and packages.lock.json.
What it assumes
Assumes basic GitHub Actions workflow configuration and introduces cache paths, keys, restore prefixes, and hashFiles usage.
What you can do after
Operate/configure GitHub Actions caches with deterministic keys, restore prefixes, and lockfile-driven invalidation.
How it connects
Connects cache keys with GitHub Actions jobs, runner operating systems, lockfiles, package managers, and container-image caching.

Also explained in

Compare how 3 books explain cache key →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of GitHub Actions in Action: Continuous integration and delivery for DevOps. The section links point to the parts of the book it draws on.