Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,11 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6

- name: Cache Primes
id: cache-primes
uses: actions/cache@v4
uses: actions/cache@v5
with:
path: prime-numbers
key: ${{ runner.os }}-primes
Expand All @@ -154,11 +154,11 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6

- name: Restore cached Primes
id: cache-primes-restore
uses: actions/cache/restore@v4
uses: actions/cache/restore@v5
with:
path: |
path/to/dependencies
Expand All @@ -169,7 +169,7 @@ jobs:
.
- name: Save Primes
id: cache-primes-save
uses: actions/cache/save@v4
uses: actions/cache/save@v5
with:
path: |
path/to/dependencies
Expand Down Expand Up @@ -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.

```yaml
- uses: actions/cache@v4
- uses: actions/cache@v5
with:
path: |
path/to/dependencies
Expand All @@ -242,7 +242,7 @@ Additionally, you can use arbitrary command output in a cache key, such as a dat
echo "date=$(/bin/date -u "+%Y%m%d")" >> $GITHUB_OUTPUT
shell: bash

- uses: actions/cache@v4
- uses: actions/cache@v5
with:
path: path/to/dependencies
key: ${{ runner.os }}-${{ steps.get-date.outputs.date }}-${{ hashFiles('**/lockfiles') }}
Expand All @@ -262,9 +262,9 @@ Example:

```yaml
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6

- uses: actions/cache@v4
- uses: actions/cache@v5
id: cache
with:
path: path/to/dependencies
Expand Down Expand Up @@ -292,11 +292,11 @@ jobs:
build-linux:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6

- name: Cache Primes
id: cache-primes
uses: actions/cache@v4
uses: actions/cache@v5
with:
path: prime-numbers
key: primes
Expand All @@ -307,7 +307,7 @@ jobs:

- name: Cache Numbers
id: cache-numbers
uses: actions/cache@v4
uses: actions/cache@v5
with:
path: numbers
key: primes
Expand All @@ -319,11 +319,11 @@ jobs:
build-windows:
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6

- name: Cache Primes
id: cache-primes
uses: actions/cache@v4
uses: actions/cache@v5
with:
path: prime-numbers
key: primes
Expand Down
40 changes: 20 additions & 20 deletions caching-strategies.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ This document lists some of the strategies (and example workflows if possible) w
jobs:
build:
runs-on: ubuntu-latest
- uses: actions/cache@v4
- uses: actions/cache@v5
with:
key: ${{ some-metadata }}-cache
```
Expand All @@ -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.

```yaml
- uses: actions/cache@v4
- uses: actions/cache@v5
with:
path: |
path/to/dependencies
Expand All @@ -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.

```yaml
- uses: actions/cache@v4
- uses: actions/cache@v5
with:
path: |
path/to/dependencies
Expand All @@ -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.

```yaml
- uses: actions/cache@v4
- uses: actions/cache@v5
with:
path: |
path/to/dependencies
Expand All @@ -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.

```yaml
- uses: actions/cache@v4
- uses: actions/cache@v5
with:
path: |
path/to/dependencies
Expand All @@ -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.

```yaml
- uses: actions/cache@v4
- uses: actions/cache@v5
with:
path: |
path/to/dependencies
Expand Down Expand Up @@ -146,9 +146,9 @@ In case you are using a centralized job to create and save your cache that can b

```yaml
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6

- uses: actions/cache/restore@v4
- uses: actions/cache/restore@v5
id: cache
with:
path: path/to/dependencies
Expand All @@ -171,9 +171,9 @@ You can use the output of this action to exit the workflow on cache miss. This w

```yaml
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6

- uses: actions/cache/restore@v4
- uses: actions/cache/restore@v5
id: cache
with:
path: path/to/dependencies
Expand All @@ -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.

```yaml
- uses: actions/cache/restore@v4
- uses: actions/cache/restore@v5
id: restore-cache
with:
path: |
Expand All @@ -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:
path: |
path/to/dependencies
Expand All @@ -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

```yaml
uses: actions/cache/restore@v4
uses: actions/cache/restore@v5
id: restore-cache
with:
key: cache-${{ hashFiles('**/lockfiles') }}
Expand All @@ -228,15 +228,15 @@ with:
Case 1: Where an user would want to reuse the key as it is

```yaml
uses: actions/cache/save@v4
uses: actions/cache/save@v5
with:
key: ${{ steps.restore-cache.outputs.cache-primary-key }}
```

Case 2: Where the user would want to re-evaluate the key

```yaml
uses: actions/cache/save@v4
uses: actions/cache/save@v5
with:
key: npm-cache-${{hashfiles(package-lock.json)}}
```
Expand All @@ -253,12 +253,12 @@ In case of multi-module projects, where the built artifact of one project needs

```yaml
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6

- name: Build
run: ./build-parent-module.sh

- uses: actions/cache/save@v4
- uses: actions/cache/save@v5
id: cache
with:
path: path/to/dependencies
Expand All @@ -269,9 +269,9 @@ steps:

```yaml
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6

- uses: actions/cache/restore@v4
- uses: actions/cache/restore@v5
id: cache
with:
path: path/to/dependencies
Expand All @@ -280,7 +280,7 @@ steps:
- name: Install Dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: ./install.sh

- name: Build
run: ./build-child-module.sh

Expand Down
Loading
Loading