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.

How:

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.

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

Comments

0 comments

Please sign in to leave a comment.