Skip to content

If the target path doesn't match the source path, restore reports "Cache not found for input keys" #1444

Open

Description

@dylanbeattie

Hey there,

I've been trying to use the save/restore actions from two separate jobs, and after six hours of head-scratching, worked out what's going on. If the path provided to the restore command doesn't exactly match the path that was provided to the save command, the restore action reports "Cache not found for input keys". Here's a repro case. Run this in any repo, then look at the action console output; the second fetch-stuff-from-cache job won't restore any files.

name: cache-test
on:
  push:
    branches: ["main"]
    paths:
      - '.github/workflows/caching-test.yml'
  workflow_dispatch:
jobs:
  cache-some-stuff:
    runs-on: ubuntu-latest
    steps:
      - name: Create some files
        run: |
          mkdir my-files
          echo "Hello" > my-files/file0001.txt
          echo "World" > my-files/file0002.txt
          ls -lR
      - uses: actions/cache/save@v4
        id: put-files-in-cache
        with:
          path: my-files
          key: my-cached-files-${{ github.run_id }}
  fetch-stuff-from-cache-success:
    runs-on: ubuntu-latest
    steps:
      - name: restore files from from cache
        uses: actions/cache/restore@v4
        with:
          path: my-files
          key: my-cached-files
      - name: List files
        run: ls -lR
  fetch-stuff-from-cache-failure:
    runs-on: ubuntu-latest
    steps:
      - name: restore files from from cache
        uses: actions/cache/restore@v4
        with:
          path: this-will-fail-because-the-path-is-not-the-same
          key: my-cached-files
      - name: List files
        run: ls -lR

It's not clear anywhere in the documentation or in the error message that you can only restore cached content to the same path it was originally cached from - presumably because if you're using the cache action rather than separate save/restore actions there's no way to specify a different path.

Is there any underlying technical reason I can't restore cached content to a different path than it was originally saved from? If not, this would make the save/restore combination far more flexible for caching files in complex build jobs - but if this isn't possible, could the restore error message be updated to make it explicit that the target path doesn't match and that's the reason it can't find anything?

Thanks,

Dylan

Activity

  1. Sam13 commented on Nov 9, 2024

    @Sam13

    Is there any underlying technical reason I can't restore cached content to a different path than it was originally saved from? If not, this would make the save/restore combination far more flexible for caching files in complex build jobs

    That would be a huge advantage.
    +1
    Probably with an optional extra parameter for the restore action this would be possible.

  2. deitChi commented on Jan 29, 2025

    @deitChi

    Although it doesn't report the Version hash during load, I believe that's what's causing the cache miss.

    This would be a great feature! I ended up exploring this, as I get permission errors when restoring cached files to /usr/local/bin.

    So an input for the load action with something like this would be great!:

    - name: restore files from from cache
      uses: actions/cache/restore@v4
      with:
        path: /tmp/myfile
        save-path: /usr/local/bin/myfile
        key: my-cached-files
    
  3. daanzu commented on Sep 18, 2025

    @daanzu

    I'd like to point out the incredibly deceptive error message here. It should clearly state the problem is the path, not the key!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions