Clear Project Dependency Cache

Cache Clearing 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.

 

Manual Cache Clearing

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 to 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?
49 out of 224 found this helpful

Comments

1 comment

Article is closed for comments.