Skip to content

Skip download option (allow only to check if cache exists for the given key) #901

Closed

Description

@DaSchTour

I have some jobs that do actions if cache there is a cache hit or not or add stuff to the cache, but they actually do not care about the content of the cache. I think it would be convenient to have an option not download the content of the cache.

Activity

  1. bogdandrutu commented on Sep 1, 2022

    @bogdandrutu

    I would like this as well.

  2. Wambosa commented on Sep 1, 2022

    @Wambosa

    I am running into an issue that might just be related to this.
    Its unclear to me if I can just explicit set the cache.

    The docs say key is required :/
    In my case, I want to set the cache and not try to download it.
    Perhaps it would be nice if key became optional and was used to flag explicit set behavior?

    setupJob:
        steps:
        - uses: actions/checkout@v2
    
        - name: Restore Workspace if its there
          id: try-restore
          uses: actions/cache@v3
          with:
            path: ${{ github.workspace }}
            key: restore-${{ hashFiles('package-lock.json', 'Makefile') }}
          
      ... (other logic) ...
          
        - name: Cache Workspace
          if: steps.try-restore.outputs.cache-hit != 'true'
          uses: actions/cache@v3
          with:
            path: ${{ github.workspace }}
            restore-keys: |
              restore-${{ hashFiles('package-lock.json', 'Makefile', 'src/', 'infra/') }}
              other-job-can-get-my-workspace-with-const-key
    

    other job

    otherjob:
        steps:
        - name: Get working directory 
          uses: actions/cache@v3
          with:
            path: ${{ github.workspace }}
            key: other-job-can-get-my-workspace-with-const-key
    
  3. bishal-pdMSFT commented on Sep 11, 2022

    @bishal-pdMSFT

    @DaSchTour @bogdandrutu not sure I understand the rationale here of just checking existence of cache but not use it. Could you please share some use cases.
    Please note that now we have GitHub REST API and gh CLI extension to get a cache metadata by key. You can use these for such cases instead.

  4. added
    area:granular-control
    on Sep 11, 2022
  5. DaSchTour commented on Sep 12, 2022

    @DaSchTour
    Author

    @bishal-pdMSFT well it's not really just existence, it's also to "initialize" the cache if needed. The workflow simplfied looks like this.

    1. action/cache
    2. do something if cache is not hit adding stuff to the cache

    If there is a cache hit I skip the second step, if not I add something to the cache. So if the cache is hit I don't care what's actually in the cache. But if cache is not hit I need to have it to be able to put something in there.

  6. cdce8p commented on Oct 23, 2022

    @cdce8p
    Contributor

    Could you please share some use cases.

    To expand one what has already been said. In some the workflows I've seen, the dependency install and tests happen in separate jobs. I.e.

    • Job 1: Check if cache exists, if not download / build dependencies and create new cache entry
    • Job 2 - X: Different test runners. Restore environment from cache. If restore failed, fail test. Run tests, linters, etc.

    If for Job 1 a useable cache already exists, there is no point in spending the extra time restoring it as it won't get used anyway.

    Please note that now we have GitHub REST API and gh CLI extension to get a cache metadata by key. You can use these for such cases instead.

    True, although that's probably more complicate. It isn't enough to check if a specific key exists, due to the way restore works it must be from the same or base ref. The action does this check already. I imagine it's much easier to add a simple switch to skip restore.

    --
    Note: There is also #831 proposing something similar.

  7. bogdandrutu commented on Oct 23, 2022

    @bogdandrutu

    We have the same use case, since we have a large repo, we want to run tests in multiple jobs, hence we cache all go dependencies initially then run tests in separate jobs.

  8. kotewar commented on Dec 7, 2022

    @kotewar
    Contributor

    Hey all, 👋🏽

    We have created a discussion with a proposal that we feel will solve this problem, do let us know your feedback, thanks 😊

  9. bogdandrutu commented on Dec 8, 2022

    @bogdandrutu

    @kotewar unfortunately that discussion completely ignores this use case :)

  10. Wambosa commented on Dec 8, 2022

    @Wambosa

    We have the same use case, since we have a large repo, we want to run tests in multiple jobs, hence we cache all go dependencies initially then run tests in separate jobs.

    @bogdandrutu, yes we do this same exact thing. For reference to everyone else here. It looks something like this:
    image

    The very first job is responsible for loading all the deps into the cache.

    This currently works, however it is somewhat wasteful and could be better if we could control explicit set on cache-key invalidation.

  11. cdce8p commented on Dec 23, 2022

    @cdce8p
    Contributor

    I've implemented a possible solution with #1041. A dry-run: true option would work well from my initial testing.
    If someone else wants to test it

          - uses: cdce8p/cache@restore-dry-run
            with:
              ...
              dry-run: true
  12. changed the title [-]Skip download option[/-] [+]Skip download option (allow only to check if cache exists for the given key)[/+] on Dec 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

area:granular-control

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions