Daily Cache
Note: This is not required or recommended for many use cases, but can prove potentially useful for some instances.
For example, if you are building static blog sites that fetch from external API's, you may want to build with a new cache periodically to ensure any new information is fetched.
Solution
Early in your job, create a file containing today's date without a timestamp:
- run: date +%F > date
You can now use this file to test against when choosing when to rebuild cache by utilizing the checksum template.
- restore_cache:
keys:
- date-cache-{{ checksum "date" }}
- save_cache:
key: date-cache-{{ checksum "date" }}
paths:
- "/docs"
The checksum of the date
file will remain static until the next day, at which point a new cache will be created.
Note: The old caches will still exist under a different cache key and will expire after 15 days as per our retention policy:
https://circleci.com/docs/2.0/caching/#cache-expiration
Comments
Article is closed for comments.