Additional time based cache key templates and cache TTL


#1

There is currently no option to have cache valid for limited time.
epoch is pretty much useless, invalidating cache every second.
It would be nice to have additional templates for “timestamp today at 00:00” and “timestamp 1st of this month at 00:00”

Better yet would be an option to specify cache TTL on save_cache step. That would solve stale cache problem nicely while keeping immutability concept. May be s3 object expiration can be utilized for that.


#3

I opened an internal feature request for this. :slight_smile:


#4

I tried to work around this by setting MONTH="$(date '+%Y-%m')" in my bashrc file and using {{ .Environment.MONTH }} in the cache key, but it turns out the cache steps don’t use the BASH_ENV variable, so there’s no way to hack around this.

Making them honour the BASH_ENV would allow for really flexible cache keys on custom vars. The builtin vars are quite limited. Please add a way to do this!


#5

I ended up using this workaround:

                command: |
                    date '+%Y' > ~/YEAR
                    date '+%Y-%m' > ~/MONTH
                    date '+%Y-%W' > ~/WEEK

and then using those in my cache keys:

- my-cache-key-{{ checksum "~/WEEK" }}

not quite as good as ‘cache this for the next 7 days’ but almost.


#6