Overview
Dependency caching with the CircleCI built-in cache system requires setting a cache key using a template formatted string. Such as
myapp-{{ checksum "package-lock.json" }}
which would generate a cache key like
myapp-+KlBebDceJh_zOWQIAJDLEkdkKoeldAldkaKiallQ
This string means that the cache will automatically know to update if you make any changes to your package-lock.json file.
Deleting a cache
It is not possible to delete a cache ad-hoc. When a cache is created, it is tagged with an expiration date. The file will expire on that date and time. The retention period is set in your organisation's Plan page under Usage Controls.
Incrementing a cache key
To rebuild your cache manually you can add a versioning key to your cache key template.
You can add a versioning prefix to the beginning of your keys and increment it when you want to clear out and rebuild the cache. UI environment variables are useful here, as you could set a variable like CACHE_VERSION=v1
in your project settings, then add that to your config.
This is written as:
myapp-{{ .Environment.CACHE_VERSION }}-{{checksum "package-lock.json" }}
which would expand to
myapp-v1-+KlBebDceJh_zOWQIAJDLEkdkKoeldAldkaKiallQ
If you need to manually update the cache, update the environment variable in the project settings to v2
which changes the cache key and results in a new cache being generated.
Comments
Regarding CircleCI 2 workflows, please take note that environment variables are not supported yet in cache keys, some workarounds are given in https://discuss.circleci.com/t/cannot-use-circle-yml-environment-variables-in-cache-keys/10994/20
Shame.
Article is closed for comments.