Creating a "daily" cache

Here is a trick to give yourself a cache that is cleared daily. This is not required or recommended for many use cases but can prove potentially useful for some instances.

For instance, in building static blog sites that fetch from external API's, you may want to clear your cache periodically to ensure any new information is fetched.


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:
            - date-cache-{{ checksum "date" }}
      - save_cache:
            key: date-cache-{{ checksum "date" }}
                - "/docs"

 The checksum of the date file will remain static until the next day, at which point a new cache will be created.

Was this article helpful?
16 out of 16 found this helpful



Please sign in to leave a comment.