Clear project dependency cache

Cache Clearing

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.

Sometimes you may want to clear/rebuild your cache manually. A strategy that is helpful is by adding 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 do your config.

This is written as:

myapp-{{ .Environment.CACHE_VERSION }}-{{checksum "package-lock.json" }}  

which would expand to 

myapp-v1-+KlBebDceJh_zOWQIAJDLEkdkKoeldAldkaKiallQ

and if you need to manually update the cache all you need to do is update the environment variable in the project settings to v2 which changes the cache key and results in a new cache being generated.

Was this article helpful?
18 out of 92 found this helpful

Comments

1 comment

Please sign in to leave a comment.