Skip to content

Commit 9e11fdd

Browse files
committed
Cache demo
1 parent 93c96de commit 9e11fdd

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

.github/workflows/cache.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Cache
2+
3+
on:
4+
push:
5+
schedule:
6+
- cron: "0 0 1 * *" # Midnight every month (UTC)
7+
workflow_dispatch:
8+
9+
jobs:
10+
build:
11+
name: Build
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- name: Cache dates
16+
uses: actions/cache@v4
17+
with:
18+
path: dates.txt
19+
key: dates-${{ github.run_id }}-${{ github.run_attempt }}
20+
restore-keys: |
21+
dates-${{ github.run_id }}-
22+
dates-
23+
24+
- name: Show dates.txt
25+
run: |
26+
if [[ -f "dates.txt" ]]; then
27+
cat dates.txt
28+
else
29+
touch dates.txt
30+
fi
31+
32+
- name: Add today to top of dates.txt
33+
run: |
34+
date -u "+%Y-%m-%d %H:%M:%S UTC" > today.txt
35+
cat today.txt dates.txt | head -n 5 > new_dates.txt
36+
cp new_dates.txt dates.txt
37+
38+
- name: Show updated dates.txt
39+
run: cat dates.txt

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,19 @@ You may also get an unexpected result depending on the event that triggered the
5555

5656
</details>
5757

58+
## cache.yml
59+
60+
<details>
61+
62+
<summary>Caching data.</summary>
63+
64+
<br/>You can cache files, directories, or a combination of them. If you want to test for a cache hit, keep in mind that it only occurs if it matches the primary cache `key`. A partial match on `restore-keys` is still considered a cache miss.
65+
66+
[cache.yml](.github/workflows/cache.yml)
67+
- Shows various contexts
68+
69+
</details>
70+
5871
## context.yml
5972

6073
<details>

0 commit comments

Comments
 (0)