You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Partially matching a key and not setting cache-hit to true is just ..... stupid #1808
For whoever's looking for a solution, here's what I found.
You need to replace this:
- uses: actions/cache@v6
id: my-step-cache
with:
path: <path-to-cache>
key: <cache-key>
- name: Build
# Issue: if partial hit happens, `path` is still written, but cache-hit is set to false. So, the build still executes
if: steps.my-step-cache.outputs.cache-hit != 'true'
run: <build command>
With this:
- uses: actions/cache/restore@v6
id: my-step-cache
with:
path: <path-to-cache>
key: <cache-key>
restore-keys: |
<prefix1 of cache-key>
<prefix2 of cache-key>
...
- name: Record whether any cache was restored
id: my-step-cache-status
env:
MATCHED_KEY: ${{ steps.my-step-cache.outputs.cache-matched-key }}
run: |
if [ -n "$MATCHED_KEY" ]; then
echo "restored=true" >> "$GITHUB_OUTPUT"
else
echo "restored=false" >> "$GITHUB_OUTPUT"
fi
- name: Build
if: steps.my-step-cache-status.outputs.restored != 'true'
run: <build command>
# Compared to actions/cache, restore doesn't automatically write to the cache
- uses: actions/cache/save@v6
if: steps.my-step-cache-status.outputs.restored != 'true'
with:
path: <path-to-cache>
key: <cache-key>
The restore step sets the restored variable to true for both exact and partial matches. However, you need to explicitly enumerate the prefixes of the key.
Activity
RazorBest commentedon Nov 27, 2026
For whoever's looking for a solution, here's what I found.
You need to replace this:
With this:
The restore step sets the
restoredvariable to true for both exact and partial matches. However, you need to explicitly enumerate the prefixes of the key.