13
5

More than 5 years have passed since last update.

CircleCIのsave_cache、restore_cacheについて

Posted at

はじめに

最近、CI/CD周りの構築に関心があり、CircleCIについて少し触ってみました。
そこで、キャッシュ周りについて簡単なメモを残しておきたいと思います。

save_cache

下記のように、pathとkeyを設定する事でキャッシュできる。
また、keyの指定時にchecksumを用いて、yarn.lockをSHA256でhash化しています。


version: 2
jobs:
  build:
    docker:
      - image: circleci/node:10.8.0
    working_directory: ~/hoge
    steps:
     ...do something
      - save_cache:
          key: v1-hoge-{{ .Branch }}-{{ checksum "yarn.lock" }}
          paths:
            - ~/hoge/node_modules

restore_cache

save_cacheで指定した同じkeyを用いて、キャッシュをリストアします。
こうする事により、キャッシュしたnode_modulesを使用することができます。
※yarn.lockの中身に変更があれば、hash値も変わるので、キャッシュされたnode_modulesは使用されません。


steps:
  - restore_cache:
      key: v1-hoge-{{ .Branch }}-{{ checksum "yarn.lock" }}

参考

13
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
13
5