question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cache always hits even when the files change

See original GitHub issue

I’m using GH actions to publish a static site that reflects the current OpenShift versions. The code generates a json file every time it is executed and then it renders an html file. I use the cache action to cache the pip dependencies successfully and I want to use the cache to do the same but for the json file that is generated like so:

    - name: versions.json cache
      uses: actions/cache@v2.1.1
      env:
        cache-name: versions-json
      with:
        path: versions.json
        key: ${{ env.cache-name }}-${{ hashFiles('versions.json') }}

But it turns out that the cache always hits even if the file changes…

I’ve tried different combinations of the key such as ${{ env.cache-name }}-${{ hashFiles('**/versions.json') }} but the cache is never ‘refreshed’.

The repo is https://github.com/openshifttips/openshift-versions/ just in case.

Thanks!

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
dhadkacommented, Sep 4, 2020

@iranzo The example above with the run_id in the key should work for that scenario, but it will be saving to the cache each run even if versions.json doesn’t change.

This is really a limitation of how (or more correctly: when) cache keys are calculated. There is a feature request to address this (https://github.com/actions/cache/issues/135), but this hasn’t been worked on yet as far as I know.

0reactions
e-minguezcommented, Sep 10, 2020

It looks like the github.run_id variable did the trick 😃 Final result looks like this:

    - name: versions.json cache
      uses: actions/cache@v2.1.1
      env:
        cache-name: cache-versions-json
      with:
        path: versions.json
        key: ${{ env.cache-name }}-${{ github.run_id }}
        restore-keys: ${{ env.cache-name }}-

Thanks!!!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Getting cache hit even when changing appendedCacheKey
If I change appendedCacheKey between runs I still get a cache hit. ... The basic problem is that we do not use a...
Read more >
Caching Behavior of Web Browsers - F5 Networks
When a user visits a web page, the contents of that page can be stored in the browser's cache so it doesn't need...
Read more >
When hitting F5 just isn't enough! - Refresh your cache
In some (rare) cases, even though you are using shift-refresh to get new data from a webpage, the pages still seem to be...
Read more >
Make use of long-term caching - web.dev
This approach tells the browser to download the JS file, cache it and use the cached copy. The browser will only hit the...
Read more >
How to force browsers to reload cached CSS and JS files?
css or .js file EVERY time you load the page. This method still allows caching until you actually change the file and really...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found