mirror of
https://code.forgejo.org/actions/cache.git
synced 2025-04-02 04:57:46 +02:00
Moved back section to strategies
This commit is contained in:
parent
72fba45689
commit
989ccaeed0
2 changed files with 58 additions and 58 deletions
58
README.md
58
README.md
|
@ -134,64 +134,6 @@ jobs:
|
|||
key: ${{ steps.cache-primes-restore.outputs.cache-primary-key }}
|
||||
```
|
||||
|
||||
#### Saving cache once and reusing in multiple workflows
|
||||
|
||||
In case of multi-module projects, where the built artifact of one project needs to be reused in subsequent child modules, the need of rebuilding the parent module again and again with every build can be eliminated. The `actions/cache` or `actions/cache/save` action can be used to build and save the parent module artifact once, and restored multiple times while building the child modules.
|
||||
|
||||
##### Step 1 - Build the parent module and save it
|
||||
|
||||
```yaml
|
||||
name: Saving Primes
|
||||
|
||||
on: push
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Generate primes
|
||||
run: ./generate-primes.sh
|
||||
|
||||
- name: Save Primes
|
||||
id: cache-primes-save
|
||||
- uses: actions/cache/save@v3
|
||||
with:
|
||||
path: |
|
||||
path/to/dependencies
|
||||
some/other/dependencies
|
||||
key: ${{ runner.os }}-primes
|
||||
```
|
||||
|
||||
##### Step 2 - Restore the built artifact from cache using the same key and path
|
||||
|
||||
```yaml
|
||||
name: Restoring Primes
|
||||
|
||||
on: push
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Restoring Primes
|
||||
id: cache-primes-restore
|
||||
- uses: actions/cache/restore@v3
|
||||
with:
|
||||
path: |
|
||||
path/to/dependencies
|
||||
some/other/dependencies
|
||||
key: ${{ runner.os }}-primes
|
||||
.
|
||||
.
|
||||
. //remaining workflow steps continued
|
||||
```
|
||||
|
||||
> **Note**
|
||||
> You must use the `cache` or `restore` action in your workflow before you need to use the files that might be restored from the cache. If the provided `key` matches an existing cache, a new cache is not created and if the provided `key` doesn't match an existing cache, a new cache is automatically created provided the job completes successfully.
|
||||
|
||||
|
|
|
@ -252,3 +252,61 @@ steps:
|
|||
path: path/to/dependencies
|
||||
key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }}
|
||||
```
|
||||
|
||||
### Saving cache once and reusing in multiple workflows
|
||||
|
||||
In case of multi-module projects, where the built artifact of one project needs to be reused in subsequent child modules, the need of rebuilding the parent module again and again with every build can be eliminated. The `actions/cache` or `actions/cache/save` action can be used to build and save the parent module artifact once, and restored multiple times while building the child modules.
|
||||
|
||||
#### Step 1 - Build the parent module and save it
|
||||
|
||||
```yaml
|
||||
name: Saving Primes
|
||||
|
||||
on: push
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Generate primes
|
||||
run: ./generate-primes.sh
|
||||
|
||||
- name: Save Primes
|
||||
id: cache-primes-save
|
||||
- uses: actions/cache/save@v3
|
||||
with:
|
||||
path: |
|
||||
path/to/dependencies
|
||||
some/other/dependencies
|
||||
key: ${{ runner.os }}-primes
|
||||
```
|
||||
|
||||
#### Step 2 - Restore the built artifact from cache using the same key and path
|
||||
|
||||
```yaml
|
||||
name: Restoring Primes
|
||||
|
||||
on: push
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Restoring Primes
|
||||
id: cache-primes-restore
|
||||
- uses: actions/cache/restore@v3
|
||||
with:
|
||||
path: |
|
||||
path/to/dependencies
|
||||
some/other/dependencies
|
||||
key: ${{ runner.os }}-primes
|
||||
.
|
||||
.
|
||||
. //remaining workflow steps continued
|
||||
```
|
||||
|
|
Loading…
Add table
Reference in a new issue