-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update cache key creation to use date suffix #5463
Update cache key creation to use date suffix #5463
Conversation
I hope that the added explanation in the publishing guide is succinct enough. I won't be able to make changes till the evening. |
@kamilkrzyskow I was busy working on the social cards, which are now released, an we removed the caching section from the docs, since this should be part of the publishing guide (it's already mentioned there). Could you rebase your PR? |
8166eef
to
811a073
Compare
I think I did it correctly @squidfunk, the cache workflow example is still in the privacy plugin page 🤔 |
Thanks again for taking the time to explain your rationale behind the proposed changes and update the PR. Your work is very much appreciated! I think this is now good to merge, so let's give it a spin! |
Then using the whole date to make it update daily would have been better in your case 🤔 or perhaps an even more aggressive time based cache, with added hours and some modulo magic to update it even more frequently. Defining a cache name specific to certain changes is rather context specific, I didn't think it would apply to the general public, so I just used the time, as updating on each commit basically ignores the idea of cache. Perhaps you'd need to make use of the separate cache-read and cache-save workflow hmm. |
Yeah, you could probably use the |
Thanks for your input! I'm not sure |
Hmm, in your case the But let's assume there is a case where the cache directory doesn't exist. Perhaps it's possible to use some sort of conditional in the workflow using environmental variables. https://github.com/actions/cache/blob/main/save/README.md#always-save-cache Like here instead of the I am not able to check it myself in the moment. |
Okay, so I think I misread. If we split caching into both actions, we'll always save the cache and there should be no problem. If we don't do that, then GitHub will only save the cache if it was not able to restore. I'll give that a try Thanks again for your time! |
Continuation of #5460
3rd attempt at choosing the correct caching strategy, wish me luck 🙋
In my last comment in the previous PR I wrongly assumed that using separate
cache/restore
andcache/save
actions would allow to overwrite an already created cache. I tried it and unfortunately it turned out that caches are read only once created 😞🗑️
Another suggestion, when using separate actions, was to use
${{ hashFiles('.cache/**') }}
to only update the cache when it actually changes. I tried it and ultimately, I personally don't like it, this approach has multiple "traps":In the case that${{ hashFiles('.cache/**') }}
returns empty (lack of created cache) it would create a cache with only the prefix as the namemkdocs-material-
. I believe that such cache would take priority overmkdocs-material-xxx
, because therestore-keys
would first look for an identical match and then act as prefixes. Therefore there is a chance that newer caches wouldn't be used. At least I think so 😵EDIT: So, I read the action log incorrectly. If the
.cache
path doesn't exist then it won't create any cache, themkdocs-material-
cache was created, because I tried to access an incorrectgithub
context property. Hence, it kept accessing themkdocs-material-
cache afterwards 🤦path
s andkey
s to fill out. Showing people how to use theenv
could mitigate that, but I believe there would be some people missing some parts of the process.Also this approach restores the caches only via the
restore-keys
and then it can happen that${{ hashFiles('.cache/**') }}
returns the same hash as before, but the save action will still try to save and fail using the same cache. Putting this all together, it seems to be a bad design choice, a "code smell" in a way, because most cache attempts will "warn" about a failure somewhere.🗑️
Having tried the separate actions and ultimately deciding against using them, I turned to the date approach, as my last resort. By the way, I found this cache workarounds guide, to update the cache it shows an example using
github.run_id
, which basically is the same as usinggithub.sha
😅, but there is a comment# Can use time based key as well
, so I think it's the right way 🤘 .I tried it and very much liked the simplicity of adding only 1 line to the workflow file, admittedly a Linux command, which could be considered cryptic, but oh well. Once familiarising themselves with the command, users could also modify the date formatting string to change the frequency of the caches to their liking. I set the frequency to 1 week. 🎉