@ -224,7 +224,7 @@ A cache key can include any of the contexts, functions, literals, and operators
For example, using the [`hashFiles`](https://docs.github.com/en/actions/learn-github-actions/expressions#hashfiles) function allows you to create a new cache when dependencies change.
For example, using the [`hashFiles`](https://docs.github.com/en/actions/learn-github-actions/expressions#hashfiles) function allows you to create a new cache when dependencies change.
```yaml
```yaml
- uses: actions/cache@v4
- uses: actions/cache@v5
with:
with:
path: |
path: |
path/to/dependencies
path/to/dependencies
@ -242,7 +242,7 @@ Additionally, you can use arbitrary command output in a cache key, such as a dat
@ -12,7 +12,7 @@ This document lists some of the strategies (and example workflows if possible) w
jobs:
jobs:
build:
build:
runs-on: ubuntu-latest
runs-on: ubuntu-latest
- uses: actions/cache@v4
- uses: actions/cache@v5
with:
with:
key: ${{ some-metadata }}-cache
key: ${{ some-metadata }}-cache
```
```
@ -24,7 +24,7 @@ In your workflows, you can use different strategies to name your key depending o
One of the most common use case is to use hash for lockfile as key. This way, same cache will be restored for a lockfile until there's a change in dependencies listed in lockfile.
One of the most common use case is to use hash for lockfile as key. This way, same cache will be restored for a lockfile until there's a change in dependencies listed in lockfile.
```yaml
```yaml
- uses: actions/cache@v4
- uses: actions/cache@v5
with:
with:
path: |
path: |
path/to/dependencies
path/to/dependencies
@ -37,7 +37,7 @@ One of the most common use case is to use hash for lockfile as key. This way, sa
If cache is not found matching the primary key, restore keys can be used to download the closest matching cache that was recently created. This ensures that the build/install step will need to additionally fetch just a handful of newer dependencies, and hence saving build time.
If cache is not found matching the primary key, restore keys can be used to download the closest matching cache that was recently created. This ensures that the build/install step will need to additionally fetch just a handful of newer dependencies, and hence saving build time.
```yaml
```yaml
- uses: actions/cache@v4
- uses: actions/cache@v5
with:
with:
path: |
path: |
path/to/dependencies
path/to/dependencies
@ -54,7 +54,7 @@ The restore keys can be provided as a complete name, or a prefix, read more [her
In case of workflows with matrix running for multiple Operating Systems, the caches can be stored separately for each of them. This can be used in combination with hashfiles in case multiple caches are being generated per OS.
In case of workflows with matrix running for multiple Operating Systems, the caches can be stored separately for each of them. This can be used in combination with hashfiles in case multiple caches are being generated per OS.
```yaml
```yaml
- uses: actions/cache@v4
- uses: actions/cache@v5
with:
with:
path: |
path: |
path/to/dependencies
path/to/dependencies
@ -73,7 +73,7 @@ Caches scoped to the particular workflow run id or run attempt can be stored and
On similar lines, commit sha can be used to create a very specialized and short lived cache.
On similar lines, commit sha can be used to create a very specialized and short lived cache.
```yaml
```yaml
- uses: actions/cache@v4
- uses: actions/cache@v5
with:
with:
path: |
path: |
path/to/dependencies
path/to/dependencies
@ -86,7 +86,7 @@ On similar lines, commit sha can be used to create a very specialized and short
Cache key can be formed by combination of more than one metadata, evaluated info.
Cache key can be formed by combination of more than one metadata, evaluated info.
```yaml
```yaml
- uses: actions/cache@v4
- uses: actions/cache@v5
with:
with:
path: |
path: |
path/to/dependencies
path/to/dependencies
@ -148,7 +148,7 @@ In case you are using a centralized job to create and save your cache that can b
steps:
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v4
- uses: actions/cache/restore@v4
- uses: actions/cache/restore@v5
id: cache
id: cache
with:
with:
path: path/to/dependencies
path: path/to/dependencies
@ -173,7 +173,7 @@ You can use the output of this action to exit the workflow on cache miss. This w
steps:
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v4
- uses: actions/cache/restore@v4
- uses: actions/cache/restore@v5
id: cache
id: cache
with:
with:
path: path/to/dependencies
path: path/to/dependencies
@ -194,7 +194,7 @@ steps:
If you want to avoid re-computing the cache key again in `save` action, the outputs from `restore` action can be used as input to the `save` action.
If you want to avoid re-computing the cache key again in `save` action, the outputs from `restore` action can be used as input to the `save` action.
```yaml
```yaml
- uses: actions/cache/restore@v4
- uses: actions/cache/restore@v5
id: restore-cache
id: restore-cache
with:
with:
path: |
path: |
@ -204,7 +204,7 @@ If you want to avoid re-computing the cache key again in `save` action, the outp
.
.
.
.
.
.
- uses: actions/cache/save@v4
- uses: actions/cache/save@v5
with:
with:
path: |
path: |
path/to/dependencies
path/to/dependencies
@ -219,7 +219,7 @@ On the other hand, the key can also be explicitly re-computed while executing th
Let's say we have a restore step that computes key at runtime
Let's say we have a restore step that computes key at runtime
```yaml
```yaml
uses: actions/cache/restore@v4
uses: actions/cache/restore@v5
id: restore-cache
id: restore-cache
with:
with:
key: cache-${{ hashFiles('**/lockfiles') }}
key: cache-${{ hashFiles('**/lockfiles') }}
@ -228,7 +228,7 @@ with:
Case 1: Where an user would want to reuse the key as it is
Case 1: Where an user would want to reuse the key as it is
@ -76,10 +76,10 @@ Using [NuGet lock files](https://docs.microsoft.com/nuget/consume-packages/packa
```
```
Depending on the environment, huge packages might be pre-installed in the global cache folder.
Depending on the environment, huge packages might be pre-installed in the global cache folder.
With `actions/cache@v4` you can now exclude unwanted packages with [exclude pattern](https://github.com/actions/toolkit/tree/main/packages/glob#exclude-patterns)
From `actions/cache@v3` onwards, you can now exclude unwanted packages with [exclude pattern](https://github.com/actions/toolkit/tree/main/packages/glob#exclude-patterns)
```yaml
```yaml
- uses: actions/cache@v4
- uses: actions/cache@v5
with:
with:
path: |
path: |
~/.nuget/packages
~/.nuget/packages
@ -96,7 +96,7 @@ Or you could move the cache folder like below.
@ -305,7 +305,7 @@ We cache the elements of the Cabal store separately, as the entirety of `~/.caba
> **Note** Ensure no Gradle daemons are running anymore when your workflow completes. Creating the cache package might fail due to locks being held by Gradle. Refer to the [Gradle Daemon documentation](https://docs.gradle.org/current/userguide/gradle_daemon.html) on how to disable or stop the Gradle Daemons.
> **Note** Ensure no Gradle daemons are running anymore when your workflow completes. Creating the cache package might fail due to locks being held by Gradle. Refer to the [Gradle Daemon documentation](https://docs.gradle.org/current/userguide/gradle_daemon.html) on how to disable or stop the Gradle Daemons.
```yaml
```yaml
- uses: actions/cache@v4
- uses: actions/cache@v5
with:
with:
path: |
path: |
~/.gradle/caches
~/.gradle/caches
@ -319,7 +319,7 @@ We cache the elements of the Cabal store separately, as the entirety of `~/.caba
@ -12,7 +12,7 @@ A cache today is immutable and cannot be updated. But some use cases require the
```yaml
```yaml
- name: update cache on every commit
- name: update cache on every commit
uses: actions/cache@v4
uses: actions/cache@v5
with:
with:
path: prime-numbers
path: prime-numbers
key: primes-${{ runner.os }}-${{ github.run_id }} # Can use time based key as well
key: primes-${{ runner.os }}-${{ github.run_id }} # Can use time based key as well
@ -21,7 +21,7 @@ A cache today is immutable and cannot be updated. But some use cases require the
```
```
Please note that this will create a new cache on every run and hence will consume the cache [quota](./README.md#cache-limits).
Please note that this will create a new cache on every run and hence will consume the cache [quota](./README.md#cache-limits).
## Use cache across feature branches
## Use cache across feature branches
Reusing cache across feature branches is not allowed today to provide cache [isolation](https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#restrictions-for-accessing-a-cache). However if both feature branches are from the default branch, a good way to achieve this is to ensure that the default branch has a cache. This cache will then be consumable by both feature branches.
Reusing cache across feature branches is not allowed today to provide cache [isolation](https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#restrictions-for-accessing-a-cache). However if both feature branches are from the default branch, a good way to achieve this is to ensure that the default branch has a cache. This cache will then be consumable by both feature branches.