Clear Dependency Cache

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.

 

Resources

Managing CircleCI caches

Caching strategies

Was this article helpful?
49 out of 226 found this helpful

Comments

1 comment

Article is closed for comments.