cache icon indicating copy to clipboard operation
cache copied to clipboard

Add an output to differentiate between partial and full matches

Open Flamefire opened this issue 3 years ago • 2 comments

Currently outputs.cache-hit can be used to check if an "exact match" for a cache was found and restored.

In some workflows there is a need for updating a cache entry and basically doing that continuously. E.g. for cron-task workflows where an old cache is loaded, worked on then saved and should be reused for the next cron-invoke

The current best approach to support this is:

    - uses: actions/cache@v2
      id: cache-test
      with:
        path: cacheFolder
        key: cache-${{ github.run_id }}
        restore-keys: cache-

This will create a unique key per cache but restore the latest one. As long as this is run once a week the cache will "persist" long enough to be reused by the next run.

Now the problem is that a step guarded by if: steps.cache-test.outputs.cache-hit != 'true' is always executed because it did restore a cache just not an exact hit which is by design. But now I can't run a specific step only if no cache was found at all.

So I'd like a steps.cache-test.outputs.cache-restored output that is true when ANY cache was restored even those with partial matches

Flamefire avatar Sep 05 '20 18:09 Flamefire

This issue is stale because it has been open for 365 days with no activity. Leave a comment to avoid closing this issue in 5 days.

github-actions[bot] avatar Dec 23 '21 08:12 github-actions[bot]

Not stale

Flamefire avatar Dec 23 '21 11:12 Flamefire

There is work going on here. There was a similar PR. You may want to track work related to granular cache control here: https://github.com/actions/cache/discussions/1020

Phantsure avatar Dec 13 '22 07:12 Phantsure

We have added a new restore action that outputs the name of the primary key and the matched key, these outputs can be used to achieve the desired outcome. Hence closing this issue.

kotewar avatar Dec 27 '22 15:12 kotewar