actions/cache@v6

Cache artifacts like dependencies and build outputs to improve workflow execution time

At a glance

Latest major
v6
Repository
actions/cache
Inputs
8 (2 required)
Outputs
1
Runs using
node24
License
MIT
Last checked

Inputs and outputs come straight from the action's official action.yml. See our editorial standards.

Usage

- uses: actions/cache@v6

When to use it and common pitfalls

Use this action to cache artifacts like dependencies and build outputs in order to improve workflow execution time. A common pitfall is relying on `restore-keys` for a cache hit, which results in the `cache-hit` output returning false even when a stale cache is restored.

Generated by an AI model from the input and output descriptions in the action's own action.yml. Check the input descriptions below before relying on it.

Inputs

NameRequiredDefaultDescription
pathYesnoneA list of files, directories, and wildcard patterns to cache and restore
keyYesnoneAn explicit key for restoring and saving the cache
restore-keysNononeAn ordered multiline string listing the prefix-matched keys, that are used for restoring stale cache if no cache hit occurred for key. Note `cache-hit` returns false in this case.
upload-chunk-sizeNononeThe chunk size used to split up large files during upload, in bytes
enableCrossOsArchiveNofalseAn optional boolean when enabled, allows windows runners to save or restore caches that can be restored or saved respectively on other platforms
fail-on-cache-missNofalseFail the workflow if cache entry is not found
lookup-onlyNofalseCheck if a cache entry exists for the given input(s) (key, restore-keys) without downloading the cache
save-alwaysNofalseDeprecated save-always does not work as intended and will be removed in a future release. A separate `actions/cache/restore` step should be used instead. See https://github.com/actions/cache/tree/main/save#always-save-cache for more details.

Outputs

NameDescription
cache-hitA boolean value to indicate an exact match was found for the primary key

Read an output with ${{ steps.<step-id>.outputs.<name> }}; the step needs an id.

Examples

Cache npm downloads

Key the cache on the lock file so it refreshes only when dependencies change.

name: Example
on:
  push:
    branches: [main]

permissions:
  contents: read

jobs:
  example:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7
      - name: Cache
        id: cache
        uses: actions/cache@v6
        with:
          path: "~/.npm"
          key: "npm-${{ runner.os }}-${{ hashFiles('**/package-lock.json') }}"
          restore-keys: npm-${{ runner.os }}-
      - name: Use the output
        run: echo "cache-hit = ${{ steps.cache.outputs.cache-hit }}"
      - run: npm ci

Each example passed actionlint (syntax, expressions and the inputs it knows for this action). They were not run in a live repository, so replace placeholder values such as names, ARNs and paths with your own.

Something out of date or wrong? Report it on our Contact page. This page is rebuilt from the action's repository roughly once a week.