Clear project dependency cache

Cache Clearing

Depndency 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 render to a cache key that looks like myapp-+KlBebDceJh_zOWQIAJDLEkdkKoeldAldkaKiallQ so the cache will automatically know to update if you make any changes to your package-lock.json file. But 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. It would look like 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?
13 out of 75 found this helpful


1 comment

Please sign in to leave a comment.