CircleCI - Caching

Caching

-Caching lets you reuse the data from expensive fetch operations from previous jobs.
-After the initial job run, future instances of the job will run faster by not redoing work.
-A good example is package  dependency managers such as Yarn, Bundler, or Pip.
-With dependencies restored from a cache, commands like yarn install will only need to download new dependencies, if any, and not re-download everything on every build.

Caching Libraries

-The dependencies that are most important to cache during a job are the libraries on which your project depends.
  *For example, cache the libraries that are installed with pip in Python or npm for Node.js.
-Tools that are not explicitly required for your project are best stored on the Docker image
  *The docker image(s) pre-built by CircleCI have tools preinstalled that are generic for building projects using the language the image is focused on.


Example of Dependency Caching
-To save a cache of a file or directory, add the save_cache step to a job in your .circleci/config.yml file:

  steps:
    - save_cache:
        key: my-cache
        paths:
          - my-file.txt
          - my-project/my-dependencies-directory


-The path for directories is relative to the working_directory of your job. You can specify an absolute path if you choose.


Example Caching Configuration
-The following updates a cache if it changes by using checksum of pom.xml with cascading fallback:

  steps:
    - restore_cache:
        keys:
          - m2-{{ checksum "pom.xml" }}
          - m2- #used if checksum fails


Clearing Cache
-Caches are immutable so it is useful to start all your cache keys with a version prefix, for example v1-.... This enables you to regenerate all of your caches by incrementing the version in this prefix.
-In general it is safer to preserve reliability than to risk a corrupted build or to build using stale dependencies very quickly.






Documentation: https://circleci.com/docs/2.0/caching/

Komentarze

Popularne posty z tego bloga

Kubernetes

Helm

Ansible Tower / AWX